Search code examples
phpimage-scaling

PHP: How to split a blob-picture in nine parts?


I got a real hard question now: I have a blob-Picture saved in my database. Now, I want to split it into 9 Parts (like the tic-tac-toe-grid) and then I want to hide the one down right. Now I want to display these 8 parts in a random order, so you can move them and solve the puzzle (the moving could be solved with javascript).

How can I make the php-functionality? Are there existing functions for that?

Thx for help ;)


Solution

  • You can utilize GD library. There is a function imagecopy() http://www.php.net/manual/en/function.imagecopy.php within which you may copy the parts of image. For example if you have 90x90 pixels image you'll have to call it with 0,0,30,30 so that you'll have first square. Save that parts as separate images or put directly into browser and then you'll only need to manipulate them in a proper way [here: puzzle solver].