petenaylor Posted June 22, 2011 Share Posted June 22, 2011 Hi all The below piece of code resizes some size images and not others. For example, an image in landscape size of 800 pixels by 600 pixels works OK, but if I try and upload a portrait image the same dimensions it just gets stuck? Any ideas? if(!empty($_FILES['image1']['name'])) { $imagelarge = $_FILES['image1']['tmp_name']; $imagelargemain = $_FILES['image1']['name']; $pathInfo = pathinfo($imagelargemain); $rand = rand(1, 100000000000000); $name = $rand . '.' . $pathInfo['extension']; $src = imagecreatefromjpeg($imagelarge); list($width,$height)=getimagesize($imagelarge); if ($width > $height) { $newwidth=600; $newheight=($height/$width)*$newwidth; } elseif ($height > $width) { $newheight=400; $newwidth=($width/$height)*$newheight; } $center_x = (600/2)-($newwidth/2); $center_y = (400/2)-($newheight/2); $tmp=imagecreatetruecolor(600,400); $white = imagecolorallocate($tmp, 255, 255, 255); imagefill($tmp, 0, 0, $white); imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height); $filename = WEB_UPLOAD."images/adverts/". $name; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); $image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$advert_id."'") or die ("Error updating database"); } Thanks for your help. Pete Quote Link to comment https://forums.phpfreaks.com/topic/240147-php-image-resize-script/ Share on other sites More sharing options...
requinix Posted June 22, 2011 Share Posted June 22, 2011 "Gets stuck"... where? What happens? What doesn't happen? How large (in bytes) are the two files? Quote Link to comment https://forums.phpfreaks.com/topic/240147-php-image-resize-script/#findComment-1233540 Share on other sites More sharing options...
petenaylor Posted June 22, 2011 Author Share Posted June 22, 2011 Hi there The script just freezes so the browser just gets stuck on the page. I have tried it with a few different file sizes; 60KB, 700KB and 1.2MB but it does the same with each? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/240147-php-image-resize-script/#findComment-1233545 Share on other sites More sharing options...
requinix Posted June 22, 2011 Share Posted June 22, 2011 Does "freeze" mean the browser keeps trying to load something? Or it stops and you don't see anything on the page? If you do a View Source do you see anything? Have you made sure that display_errors=on in your php.ini? (If not, set it, restart the web server, and look for error messages on that page.) Quote Link to comment https://forums.phpfreaks.com/topic/240147-php-image-resize-script/#findComment-1233566 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.