Reputation: 1149
EDIT:
Is there a way to jumble arround the pixelated elements? If I have a grid of lets say 100x100 - then the pixels get very small and you can see the image sort of. So I'd like to jumble the pixelated parts. Any idea?
I'm trying to use PHP to divide an image into an equal grid, so that I could pixelate it into even parts.
It has to do with a sort of game. There is an image uploaded by some user, and I want it to be divided into x blocks (the user selects how many blocks there should be), each of the blocks would then be pixelated. When other users complete some task - one part of the pixelated block is revealed, until all pixelated parts are gone and you're left with the original image. I really don't care if the grid elements are squares, or rectangles - I just want them to be even.
As my starting points, I'm using the answer on this question PHP image pixelate?
To determine the x and y pixel size, I'm using this formula:
$gridElements = 9;
$pixelate_x = $width/sqrt($gridElements);
$pixelate_y = $height/sqrt($gridElements);
I've noticed that when using a number, whose square root is an integer - I get a more even grid.. But it's not perfect.
When trying out with a 9 block grid, and using a 1160x680 image, I get the following:
It may appear to look even, but the last row is bigger than the top 2 rows.
When I scale it to 16, the difference is quite obvious
And when trying out a 400 element grid (20x20) the 21th row appears.
So .. It's not working very well, I do want the grid to be even. Does anyone have any idea of how this could be done?
Upvotes: 2
Views: 1665
Reputation: 2744
This is because 1160 doesn't really divides itself very well, even by 3 (yes, it is not equal when using 3x3 grid either). Your greatest enemy here are integers
Upvotes: 1