Any way I can cut out a part of an existing image, and then save the result as a new image(file)?
+1
A:
imagecopy
allows you to specify x,y,w,h arguments for the src image. Combine this with imagecreatetruecolor
and you should easily be able to achieve what you want. There is even an example in the documentation for imagecopy
:
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
Andy E
2010-06-05 11:47:27
A:
You can use the gd functions for this (manual).
Load the source image (imagecreatefromstring()
can be useful, so you don't have to specify the type of the image), create an output image (imagecreatetruecolor()
) and use imagecopy()
(if you don't want to resize it). At the end use imagepng()
to output the image, or save it to a file.
Be warned that gd doesn't use image compression in memory, so your PHP process might require lots of RAM when creating a high resolution mosaic. Use imagefree()
as soon as possible.
svens
2010-06-05 11:47:59