Transform the photo into pieces (squares or rectangles)
Hi E's, I try to found the best solution, not matter if it is in imagemagick or in php, for get equal pieces of a picture like you can see in attach image.
In practice, if I have a picture width 800 * length 600, and if I want 12 pieces 4*3 (view attach image), I will get 12 pieces of 200*200 each one:
I will use get_image_size to know the size of the picture.
(variables width and length come from the get_image_size array)
$width = $width / 4; //determinate the width, it is 200px
$length = $length / 3 //determinate the length, it is 200px
Now it is the difficult part, it is give me 12 pieces 200*200 each and save in one folder of my server.
Hi @marqusG, I try your code and don't work fine.
The system create the image 1 to 12, but when I open the pieces, the pieces contain nothing! The size of each piece is about 1kb.
What is the problem?
Regards, JC
Marco Gasi
Hi, joaochagas. Have you tried my snippet as is using image attached? In my system (Windows 7) all 12 files are created, they have size of 2.68 Kb and contains the expected portion of image.I post the screenshot of my thumbnails viewed in Explorer.
If you have tried my code with your image, maybe something goes wrong with your image... How you get image?
Maybe you can post the code wich grabs your image to see if there is something wrong in it.
In your question you said to " have a picture width 800 * length 600" but now the picture has a different dimension, so there are three cases:
1 - you resize image to obtain a picture 800x600;
2 - you change accordingly the piece's size : 460/4=115, 345/3=115
3 - you decrease the number of pieces (if picture size allows it: 460/200=2.3 so in this case you can't choose this third alternative).
Besides, in your script you set $w and $h to the picture's sizes but this is wrong. If you look at my original code, $w and $h was set to piece's size, that is 200.
At the end, if you want to use for-puzzle.jpg use attached code.
Hi, with 800*600 picture work well.
Why don't work with my picture 460*345?
I change $w and $h to 115!!!
I don't have always pictures with 800*600, I can have other formats!
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=13876
http://ubuntuforums.org/archive/index.php/t-1363564.html