svgmx5 Posted December 25, 2010 Share Posted December 25, 2010 I've been working on this site that allows users to upload images to the server... the code i have right now basically uploads the file to the server and then resizes it and makes a new copy of it... Upuntil now it was working flawlessly, however now i'm getting this error: Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/content/t/h/e/thereferralpro/html/beta/region.php on line 144 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'images/projects/porncheck_star.png' is not a valid JPEG file in /home/content/t/h/e/thereferralpro/html/beta/region.php on line 144 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/content/t/h/e/thereferralpro/html/beta/region.php on line 162 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/content/t/h/e/thereferralpro/html/beta/region.php on line 165 In order for you guys to understand the error here's the code i'm using //move file to the folder before resizeing move_uploaded_file($_FILES['image']['tmp_name'], $target); //resize the image and add to server $source_pic = $target; $final_pic = $dir.$final_img_name; $max_width = 800; $max_height = 600; $src = imagecreatefromjpeg($source_pic); list($width,$height)=getimagesize($source_pic); $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ){ $tn_width = $width; $tn_height = $height; }elseif (($x_ratio * $height) < $max_height){ $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; }else{ $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $tmp=imagecreatetruecolor($tn_width,$tn_height); imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height); imagejpeg($tmp,$final_pic,80); imagedestroy($src); imagedestroy($tmp); list($width, $height, $type, $attr) = getimagesize($final_pic); Keep in mind that this code was working perfectly and now for some reason its not working anymore, and no i have not touch it at all nor i have done nay edits to this code Hope someone can help me out because i have no idea what this could be. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/ Share on other sites More sharing options...
dragon_sa Posted December 25, 2010 Share Posted December 25, 2010 It looks like is because you are uploading a png file and not a jpg file so it is causing the error Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151225 Share on other sites More sharing options...
svgmx5 Posted December 25, 2010 Author Share Posted December 25, 2010 its happening with any images... and i was able to upload all types of images before...this just started happening today iv'e checked my php info and i do have the latest gd library: bundled (2.0.34 compatible) Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151226 Share on other sites More sharing options...
svgmx5 Posted December 25, 2010 Author Share Posted December 25, 2010 Okay, so i just migrated the whole site to a different server and its working properly...could this be a server issue?? Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151238 Share on other sites More sharing options...
QuickOldCar Posted December 25, 2010 Share Posted December 25, 2010 It's probably more that the new server has error reporting disabled. It's more likely in your code itself because you can be checking what the mime should be...then of those results then do a case for any imagecreatefrom, then also a case for the output of that exact mime type as well. Look here , you are trying to create from a jpeg image when actually it's a png image. Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'images/projects/porncheck_star.png' is not a valid JPEG file in /home/content/t/h/e/thereferralpro/html/beta/region.php on line 144 Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151278 Share on other sites More sharing options...
Pikachu2000 Posted December 25, 2010 Share Posted December 25, 2010 I believe godaddy has display errors on globally. That's where you were getting the errors, yes? Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151282 Share on other sites More sharing options...
laffin Posted December 25, 2010 Share Posted December 25, 2010 Actually i encountered a similar problem awhile back, the problem is more on the image app they are using to save the image. I found some image apps did not work correctly with the gd functions while others did. An option u may have open, is to use imagemagick or netpbm to do the conversions for u, if you have these packages available to your server as well as system function in your php configuration. the other option is switch image app and testing which apps work with gd correctly. from there its just a matter of resaving the image with the ones u found to work. Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151286 Share on other sites More sharing options...
QuickOldCar Posted December 25, 2010 Share Posted December 25, 2010 You need to check them like this and then use the proper imagecreatefrom. $ext = substr($image_source, strripos($image_source, '.'),strlen($image_source)); if($ext=='.jpg' || $ext=='.jpeg'){ $image = imagecreatefromjpeg($image_source); } if($ext=='.gif'){ $image = imagecreatefromgif($image_source); } if($ext=='.png'){ $image = imagecreatefrompng($image_source); } if ($ext != ".jpg" || $ext != ".jpeg" || $ext != ".gif" || $ext != ".png") { die("<h2>$ext not allowed</h2><br /> <a href=\"javascript: history.go(-1)\">Click here to try again</a>"); } Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151287 Share on other sites More sharing options...
svgmx5 Posted December 26, 2010 Author Share Posted December 26, 2010 mm...i'll have to try that thanks everyone!! i'll let you guys know !! Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151465 Share on other sites More sharing options...
QuickOldCar Posted December 26, 2010 Share Posted December 26, 2010 Actually someone was nice enough to already write a tutorial at php freaks on image resizing and posted the code. http://www.phpfreaks.com/forums/faqcode-snippet-repository/dynamic-thumbnail-creation/ Quote Link to comment https://forums.phpfreaks.com/topic/222608-problem-with-with-image-resizing-code/#findComment-1151470 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.