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
[PHP] imagecopyresized problems
I'm trying to use imagecopyresized to generate a thumbnail image and then store the image in the proper place, but I'm running into some problems. I'm using the standard code: $src_img = imagecreatefromjpeg("../php/images/".$HTTP_POST_FILES['imagefile']['name']); if (imagesx($src_img)<$max_width){ imagejpeg($src_img); exit(); } $dst_img = imagecreate(80,60); imagecopyresized($dst_img,$src_img,0,0,80,60,80,60,imagesx($src_img),imagesy ($src_img)); imagejpeg($dst_img); this will give me this output: 3ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v2.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22ÿÀ What I need is for imagecopyresized to make a new file that I can then give a new name and copy into the files that I want it to go to, such as.. copy ($dst_img, "../php/thumbs/".$thumb_name); If I try to this, I get the following error... Warning: Unable to open 'Resource id #4' for reading: No such file or directory in /u/php/uppic.php on line 55 (uppic.php is the name of the .php script this is in) Am I missing something obvious? Thanks, Brian -- 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: 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: > > > //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(""); > > 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(" Origional: height: $height width: > $widthTarget: > height:$thumb_height width: $thumb_width"); > > //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("Variables that will be inserted into > the imagecopyresized > function"); > print("width: $width"); > print("height $height"); > print("thumb_width $thumb_width"); > print("thumb_height $thumb_height"); > > print("Display the new thumb image"); > > 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
[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: "); 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(" Origional: height: $height width: $widthTarget: height:$thumb_height width: $thumb_width"); //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("Variables that will be inserted into the imagecopyresized function"); print("width: $width"); print("height $height"); print("thumb_width $thumb_width"); print("thumb_height $thumb_height"); print("Display the new thumb image"); 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
Re: [PHP] imagecopyresized() problems
Don't know if this helps, but the following works on my system. Hugh $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
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
[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