THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.
I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.
IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.
Use pixel compression specified by type when writing the image.
$cmd = "$input -compress JPEG "; exec("convert $cmd compress.jpg");
Enhance or reduce the image contrast.
$cmd = "$input -contrast"; exec("convert $cmd contrast.jpg");
Increase the contrast in an image by stretching the range of intensity values.
$cmd = "$input -contrast-stretch \"2%\" "; exec("convert $cmd contrast-stretch.jpg");
Convolve an image with a user supplied convolution kernel.
$cmd = "$input -convolve \"-1,0,1,-1,0,1,-1,0,1\" "; exec("convert $cmd convolve.jpg");
Cut out one or more rectangular regions of the image.
$cmd = "$input -crop 133x140+80+25 +repage"; exec("convert $cmd crop.jpg");
Enable debug printout.
Array([0] =>2009-06-06T19:52:00+01:00 0:01 0.000u 6.5.1 Configure convert[3624]: utility.c/ExpandFilenames/826/Configure$array = array(); echo ""; exec("convert -debug all output.png output.jpg 2>&1", $array); echo "";
".print_r($array)."
"; echo "
( Only first two lines of output shown here. )
Decipher and restore pixels that were previously transformed by -encipher.
$cmd = "encipher.png -decipher images/passkey.txt "; exec("convert $cmd decipher.png");
Find areas that has changed between images
More information to follow.( Given a sequence of images all the same size, such as produced by -coalesce, replace the second and later images, with a smaller image of just the area that changed relative to the previous image.
The resulting sequence of images can be used to optimize an animation sequence, though will not work correctly for GIF animations when parts of the animation can go from opaque to transparent.
)
add specific global settings generally used to control coders and image processing operations
$cmd = "$input jpeg:size=200x200 ". " -thumbnail 200x200 "; exec("convert $cmd define.jpg");
( Can be used to speed up jpg conversions amongst other things )
Display the next image after pausing.
$cmd = " -dispose previous -delay 50". " -size 213x160 xc:none". " -page +0+0 $input4 -page +8+18 $input4". " -page +18+33 $input4 -page +28+48 $input4". " -page +38+63 $input4 -page +48+82 $input4". " -page +58+93 $input4 -page +68+78 $input4". " -page +78+63 $input4 -page +88+48 $input4". " -page +98+33 $input4 -page +108+18 $input4". " -page +123+0 $input4 -loop 0"; exec("convert $cmd delay.gif");
Delete the image, specified by its index, from the image sequence.
More information to follow.$cmd = " $input ( -clone 0 -thumbnail x480 -write 480_wide.jpg +delete )". " -thumbnail 64x64! null: "; exec("convert $cmd delete.jpg ");
( Do not forget to change () to \(\) on a Linux system.
+delete to delete the last image in the current image sequence. )
Set the horizontal and vertical resolution of an image for rendering to devices.
$cmd = "$input -density 200x200"; exec("convert $cmd density.jpg");