br3nn4n Posted March 4, 2009 Share Posted March 4, 2009 I have some really simple code (that needs to be reworked actually) that just takes a JPEG image and resizes it. For SOME REASON it will only work on maybe half the files I feed it. It returns nothing otherwise for no reason. The errors come out as: Notice: Undefined variable: new_width in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 28 Notice: Undefined variable: new_height in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 28 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 28 Notice: Undefined variable: new_width in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 30 Notice: Undefined variable: new_height in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 30 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 30 Warning: imagejpeg(): supplied argument is not a valid Image resource in /hermes/bosweb/web019/b193/ipw./public_html/img.php on line 33 My script is as follows: <?PHP // The file $src=$_GET['src']; if ($src == "") { $src = "noimage"; } $filename = "images/articles/" . $src . ".jpg"; // Get new dimensions list($width, $height) = getimagesize($filename); if ($width > $height) { $new_width=350; $new_height=($height/$width)*350; } // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $end = imagejpeg($image_p,'',70); ?> It works for some images, it doesn't for others...? Any idea why? I really need it to always work. Thanks so much in advance! Quote Link to comment Share on other sites More sharing options...
tivrfoa Posted March 4, 2009 Share Posted March 4, 2009 make sure it is really an jpg image. if you save a png image from the internet as jpg, so I think it won't work. Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted March 5, 2009 Author Share Posted March 5, 2009 No, thanks but that's not the problem...I'm always careful about that. I'm thinking it may be the way I get the width and height (with the list function) and maybe it's not reading the width and height. Could this be possible? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 5, 2009 Share Posted March 5, 2009 I think I see the error. You first get the width & height of the image and store the values in $width & $height list($width, $height) = getimagesize($filename); Then you have this IF statment that will set the values of $new_width and $new_height if ($width > $height) { $new_width=350; $new_height=($height/$width)*350; } Then later in the code you attempt to use additional image functions using $new_width & $new_height. But, if the IF statment was not true (i.e. The width is not greater than height) then the variables $new_width & $new_height are never defined! Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted March 9, 2009 Author Share Posted March 9, 2009 Thank you so much! I'm stupid like that some times Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.