RE: [PHP] imagecopyresized problems
Hi, imagejpeg($dst_img); This actually outputs the image, so your result is not unexpected. Try this instead: imagejpeg($dst_img, /path/and/filename/to/newfile.jpg); Regards Joakim Andersson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] imagecopyresized() problems
Hi, Output the correct headers before you output the image ie header(Content-type: image/jpeg); imagejpeg($dst_img, '', 50); Remove all print statements from this code. You cannot output anything but the headers and the image itself. Use imagecopyresampled if you can. It gives much better quality. Then to output the image from another script (not within test.php) use this: img src=test.php Regards Joakim Andersson -Original Message- From: Lance Earl [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 09, 2002 8:54 AM To: [EMAIL PROTECTED] Subject: [PHP] imagecopyresized() problems I am trying to create a piece of code that will create and display thumbnail image. When trying to send the image to a browser, I see binary data rather then an image. You can see the problem at www.dallypost.com/a/test.php The troubled cose for this page follows: ?PHP //a master image may be any image of any size //If the master image exists, the thumb will be created and output to the browser //requires path from the file system home directory as $master_image_path //requires the name of the master image as $master image //test variables -- will eventually be defined by the calling module $master_image_path = /home/html/74ranch/uploads/; $master_image = chex34.jpg; if(!isset($thumb_width)) { $thumb_width = 80; }//end if //make sure that the master file exists $master_image_all = $master_image_path; $master_image_all .= $master_image; //remove this section after coding is complete $master_image_all_link = /74ranch/uploads/; $master_image_all_link .= $master_image; print(img src = $master_image_all_link); if(file_exists($master_image_all)) { $size = getimagesize($master_image_all); $width = $size[0]; $height = $size[1]; //calculate thumb height $factor = $width / $thumb_width; $thumb_height = $height * $factor; $thumb_height = $thumb_height * .1; $thumb_height = round($thumb_height); print(P Origional: height: $height width: $widthBRTarget: height:$thumb_height width: $thumb_widthP); //build the thumbnail $src_img = imagecreatefromjpeg($master_image_all); $dst_img = imagecreate($thumb_width,$thumb_height); //$dst_img = imagecreatetruecolor($thumb_width,$thumb_height);//requires gd 2.0 or higher print(PVariables that will be inserted into the imagecopyresized function); print(BRwidth: $width); print(brheight $height); print(brthumb_width $thumb_width); print(brthumb_height $thumb_height); print(PDisplay the new thumb imageP); imagecopyresized($dst_img, $src_img, 0, 0, 0, 0,$thumb_width, $thumb_height, $width, $height); //imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);//requires gd 2.0 or higher //imagejpeg($dst_img, path and file name, 75);//saves the image to a file imagejpeg($dst_img, '', 50);//sends the image to thebrowser imagedestroy($src_img); imagedestroy($dst_img); }//end if ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagecopyresized() problems
On Monday 24 June 2002 18:57, Phil Ewington wrote: Hi, I am trying to copy and resize an image using imagecopyresized() and cannot seem to crack it. Below is the code I am using, can anyone tell me why I keep getting and invalid image resource warning and is this the src or dest parameter that the error is referring to? Both. $srcImageName = ../properties/$line[propid].jpg; $destImageName = $rm_branchref . _ . $line[propid] . .jpg; $destImage = imagecreate(275, 183); imagecopyresized($destImage, $srcImageName, 0, 0, 0, 0, 275, 183, int imagecopyresized (resource dst_im, resource src_im, ...) You're giving it a filename and not an image resource. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Arguments are extremely vulgar, for everyone in good society holds exactly the same opinion. -- Oscar Wilde */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagecopyresized() problems
Don't know if this helps, but the following works on my system. Hugh ?php $picture=../photos/$userfile_name; $size=getimagesize($picture); $height=$size[1]; $width=$size[0]; $max=200; // maximum dimension if ($height$width) { $nheight=$max; $nwidth=$width/($height/$max); } else { $nwidth=$max; $nheight=$height/($width/$max); } //header(content-type: image/jpeg); $image=imagecreatefromjpeg($picture); $image1=imagecreate($nwidth,$nheight); imagecopyresized( $image1, $image,0,0, 0,0, $nwidth, $nheight,$width,$height); imagejpeg($image1,../photos/sm_.$userfile_name.,100); ImageDestroy($image); ImageDestroy($image1); ? - Original Message - From: Phil Ewington [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, June 24, 2002 3:57 AM Subject: [PHP] imagecopyresized() problems Hi, I am trying to copy and resize an image using imagecopyresized() and cannot seem to crack it. Below is the code I am using, can anyone tell me why I keep getting and invalid image resource warning and is this the src or dest parameter that the error is referring to? $srcImageName = ../properties/$line[propid].jpg; $destImageName = $rm_branchref . _ . $line[propid] . .jpg; $destImage = imagecreate(275, 183); imagecopyresized($destImage, $srcImageName, 0, 0, 0, 0, 275, 183, imagesx($srcImageName), imagesy($srcImageName)); imageJpeg($destImage, $destImageName, 75); imagedestroy($destImage); All that happens is that I get an identical copy of the image, and not a resized one. TIA Phil Ewington. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php