Re[4]: [PHP] cropping an image script
Hi, Friday, March 14, 2003, 7:20:10 AM, you wrote: AR> I'm getting a fatal error on the following script using AR> MS Win 98 / Apache Server / PHP 4.1.1. / php_gd.dll AR> Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in AR> c:\apache\htdocs\testphoto.php on line 6 AR> Is there a workaround to this function so that I can crop part of the source AR> .jpeg? AR> Thank you. AR> Tony Ritter AR> ... AR> function AR> im_crop($cropX,$cropY,$cropH,$cropW,$source,$destination,$type='jpeg') { AR> // source image AR> $sim = ImageCreateFromJPEG($source); AR> // create the destination image AR> $dim = imagecreatetruecolor($cropW, $cropH); AR> // pass trought pixles of source image AR> for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { AR> for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { AR>$pixel = imagecolorat($sim, $j, $i); AR> imagesetpixel($dim, $j-$cropX, $i-$cropY, $pixel); AR> } AR> } AR> imagedestroy($sim); AR> ImageJPEG($dim, $destination); AR> imagedestroy($dim); AR> } AR> // example AR> im_crop(0,0,75,75,'1_data.jpeg','2_data.jpeg','jpeg'); ?>> AR> AR> Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in AR> c:\apache\htdocs\testphoto.php on line 6 AR> --- AR> [This E-mail scanned for viruses by gonefishingguideservice.com] What happens if you use imagecreate() ? -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP] cropping an image script
I'm getting a fatal error on the following script using MS Win 98 / Apache Server / PHP 4.1.1. / php_gd.dll Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in c:\apache\htdocs\testphoto.php on line 6 Is there a workaround to this function so that I can crop part of the source .jpeg? Thank you. Tony Ritter ... Fatal error: imagecreatetruecolor(): requires GD 2.0 or later in c:\apache\htdocs\testphoto.php on line 6 --- [This E-mail scanned for viruses by gonefishingguideservice.com] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] cropping an image script
Hi, Friday, March 14, 2003, 3:49:03 AM, you wrote: TR> Hi, TR> Friday, March 14, 2003, 2:07:28 AM, you wrote: AR>> In the following php script, the function takes the original file and crops AR>> to the destination file. AR>> I've ran the script using a .png file and a .jpg file. AR>> The .png works fine whereas the .jpeg file returns only part of the image AR>> along with a blue rectangle. AR>> For instance - where the original image is a 200 x 300 jpeg called: AR>> 1_data.jpeg AR>> and the destination iamge is 75x75 called: AR>> 2_data.jpeg AR>> and starting at the x,y coordinates of 0,0 - the script returns a 75x 75 AR>> file but only a sliver of the .jpg image is within the 75x75 blue square. AR>> Any help will be of assistance. AR>> Thank you. AR>> Tony Ritter AR>> AR>> The following is the php cropping script (with author credit): AR>> > // AR>> //image crop fuction . [EMAIL PROTECTED] AR>> //info at http://obala.net/en AR>> // AR>> // Yes the proses could be executed with imagecopyresized build-in function AR>> // but with this function you get the idea of how an image color set is AR>> constructed AR>> // AR>> // $cropX = source starting X AR>> // $cropY = source starting Y AR>> // $cropW = crop weigth AR>> // $cropH = crop heigh AR>> // $source = source filename AR>> // $destination = destination filename AR>> // $type = image type AR>> function AR>> im_crop($cropX,$cropY,$cropH,$cropW,$source,$destination,$type='jpeg') { AR>> // switch known types and open source image AR>> switch ($type) { AR>> case 'wbmp': $sim = ImageCreateFromWBMP($source); break; AR>> case 'gif': $sim = ImageCreateFromGIF($source); break; AR>> case 'png': $sim = ImageCreateFromPNG($source); break; AR>> default: $sim = ImageCreateFromJPEG($source); break; AR>> } AR>> // create the destination image AR>> $dim = imagecreate($cropW, $cropH); AR>> // pass trought pixles of source image AR>> for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { AR>> for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { AR>> // get RGB color info about a pixel in the source image AR>> $color = imagecolorsforindex($sim, imagecolorat($sim, $j, $i)); AR>> // insert the color in the color index of the new image AR>> $index = ImageColorAllocate($dim, $color['red'], AR>> $color['green'], $color['blue']); AR>> // plots a pixel in the new image with that color AR>> imagesetpixel($dim, $j-$cropX, $i-$cropY, $index); AR>> } AR>> } AR>> // whe dont need the sorce image anymore AR>> imagedestroy($sim); AR>> // switch known types and save AR>> switch ($type) { AR>> case 'wbmp': ImageWBMP($dim, $destination); break; AR>> case 'gif': ImageGIF($dim, $destination); break; AR>> case 'png': ImagePNG($dim, $destination); break; AR>> default: ImageJPEG($dim, $destination); break; AR>> } AR>> // free the used space of the source image AR>> imagedestroy($dim); AR>> } AR>> // example AR>> im_crop(0,0,75,75,'1_data.jpeg','2_data.jpeg','jpeg'); ?>>> TR> With jpegs you need to use $im2 = imagecreatetruecolor($x,$y) TR> and just write the pixel back using imagesetpixel($im, $x, $y, $p); TR> like this: TR> $im =imagecreatefromjpeg($filename); TR> $dim = imagecreatetruecolor($cropW, $cropH); TR> for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { TR> for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { TR> $pixel = imagecolorat($im, $x, $y); TR> imagesetpixel($dim, $j-$cropX, $i-$cropY, $pixel); TR> } TR> } TR> As it is true colour no need to use indexes. TR> -- TR> regards, TR> Tom Guess that should be imagecolorat($sim, $j, $i); :) -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cropping an image script
Hi, Friday, March 14, 2003, 2:07:28 AM, you wrote: AR> In the following php script, the function takes the original file and crops AR> to the destination file. AR> I've ran the script using a .png file and a .jpg file. AR> The .png works fine whereas the .jpeg file returns only part of the image AR> along with a blue rectangle. AR> For instance - where the original image is a 200 x 300 jpeg called: AR> 1_data.jpeg AR> and the destination iamge is 75x75 called: AR> 2_data.jpeg AR> and starting at the x,y coordinates of 0,0 - the script returns a 75x 75 AR> file but only a sliver of the .jpg image is within the 75x75 blue square. AR> Any help will be of assistance. AR> Thank you. AR> Tony Ritter AR> AR> The following is the php cropping script (with author credit): AR> // AR> //image crop fuction . [EMAIL PROTECTED] AR> //info at http://obala.net/en AR> // AR> // Yes the proses could be executed with imagecopyresized build-in function AR> // but with this function you get the idea of how an image color set is AR> constructed AR> // AR> // $cropX = source starting X AR> // $cropY = source starting Y AR> // $cropW = crop weigth AR> // $cropH = crop heigh AR> // $source = source filename AR> // $destination = destination filename AR> // $type = image type AR> function AR> im_crop($cropX,$cropY,$cropH,$cropW,$source,$destination,$type='jpeg') { AR> // switch known types and open source image AR> switch ($type) { AR> case 'wbmp': $sim = ImageCreateFromWBMP($source); break; AR> case 'gif': $sim = ImageCreateFromGIF($source); break; AR> case 'png': $sim = ImageCreateFromPNG($source); break; AR> default: $sim = ImageCreateFromJPEG($source); break; AR> } AR> // create the destination image AR> $dim = imagecreate($cropW, $cropH); AR> // pass trought pixles of source image AR> for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { AR> for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { AR> // get RGB color info about a pixel in the source image AR> $color = imagecolorsforindex($sim, imagecolorat($sim, $j, $i)); AR> // insert the color in the color index of the new image AR> $index = ImageColorAllocate($dim, $color['red'], AR> $color['green'], $color['blue']); AR> // plots a pixel in the new image with that color AR> imagesetpixel($dim, $j-$cropX, $i-$cropY, $index); AR> } AR> } AR> // whe dont need the sorce image anymore AR> imagedestroy($sim); AR> // switch known types and save AR> switch ($type) { AR> case 'wbmp': ImageWBMP($dim, $destination); break; AR> case 'gif': ImageGIF($dim, $destination); break; AR> case 'png': ImagePNG($dim, $destination); break; AR> default: ImageJPEG($dim, $destination); break; AR> } AR> // free the used space of the source image AR> imagedestroy($dim); AR> } AR> // example AR> im_crop(0,0,75,75,'1_data.jpeg','2_data.jpeg','jpeg'); ?>> With jpegs you need to use $im2 = imagecreatetruecolor($x,$y) and just write the pixel back using imagesetpixel($im, $x, $y, $p); like this: $im =imagecreatefromjpeg($filename); $dim = imagecreatetruecolor($cropW, $cropH); for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { $pixel = imagecolorat($im, $x, $y); imagesetpixel($dim, $j-$cropX, $i-$cropY, $pixel); } } As it is true colour no need to use indexes. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] cropping an image script
In the following php script, the function takes the original file and crops to the destination file. I've ran the script using a .png file and a .jpg file. The .png works fine whereas the .jpeg file returns only part of the image along with a blue rectangle. For instance - where the original image is a 200 x 300 jpeg called: 1_data.jpeg and the destination iamge is 75x75 called: 2_data.jpeg and starting at the x,y coordinates of 0,0 - the script returns a 75x 75 file but only a sliver of the .jpg image is within the 75x75 blue square. Any help will be of assistance. Thank you. Tony Ritter The following is the php cropping script (with author credit): http://obala.net/en // // Yes the proses could be executed with imagecopyresized build-in function // but with this function you get the idea of how an image color set is constructed // // $cropX = source starting X // $cropY = source starting Y // $cropW = crop weigth // $cropH = crop heigh // $source = source filename // $destination = destination filename // $type = image type function im_crop($cropX,$cropY,$cropH,$cropW,$source,$destination,$type='jpeg') { // switch known types and open source image switch ($type) { case 'wbmp': $sim = ImageCreateFromWBMP($source); break; case 'gif': $sim = ImageCreateFromGIF($source); break; case 'png': $sim = ImageCreateFromPNG($source); break; default: $sim = ImageCreateFromJPEG($source); break; } // create the destination image $dim = imagecreate($cropW, $cropH); // pass trought pixles of source image for ( $i=$cropY; $i<($cropY+$cropH); $i++ ) { for ( $j=$cropX; $j<($cropX+$cropW); $j++ ) { // get RGB color info about a pixel in the source image $color = imagecolorsforindex($sim, imagecolorat($sim, $j, $i)); // insert the color in the color index of the new image $index = ImageColorAllocate($dim, $color['red'], $color['green'], $color['blue']); // plots a pixel in the new image with that color imagesetpixel($dim, $j-$cropX, $i-$cropY, $index); } } // whe dont need the sorce image anymore imagedestroy($sim); // switch known types and save switch ($type) { case 'wbmp': ImageWBMP($dim, $destination); break; case 'gif': ImageGIF($dim, $destination); break; case 'png': ImagePNG($dim, $destination); break; default: ImageJPEG($dim, $destination); break; } // free the used space of the source image imagedestroy($dim); } // example im_crop(0,0,75,75,'1_data.jpeg','2_data.jpeg','jpeg'); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php