acidglitter Posted July 3, 2008 Share Posted July 3, 2008 okay i have this script i got off a site a few months ago and it only works 10% of the time... function open_image($file){ // Get extension $extension = strrchr($file, '.'); $extension = strtolower($extension); switch($extension){ case '.jpg': case '.jpeg': $im = @imagecreatefromjpeg($file); break; case '.gif': $im = @imagecreatefromgif($file); break; case '.png': $im = @imagecreatefrompng($file); break; // ... etc default: $im = false; break; } return $im; } // this gets the specifics for each type (i added this) switch($type){ case 'product': $open_image_url = 'images/products'; $return_url = "newproduct.php?p=2"; break; } and then it includes a page that makes the thumbnail image <?php // Load image $image = open_image("http://site.com/$open_image_url/$image_name"); if($image == false){die ('Unable to open image');} // Get original width and height $width = imagesx($image); $height = imagesy($image); // New width and height $new_width = 180; $new_height = 180; // Resample $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // The image name $mini_image=explode('.',$image_name); $mini_image_name="$mini_image[0]thumbnail.$mini_image[1]"; // Display resized image header('Content-type: image/jpeg'); imagejpeg($image_resized,"/home/html/$open_image_url/$mini_image_name"); imageDestroy($image_resized); ?> does anyone see whats wrong?? sometimes it will even say its not a valid jpg file even when it is.. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 I don't see any problems at a glance. What does the script output the other 90% of the time? Quote Link to comment Share on other sites More sharing options...
acidglitter Posted July 3, 2008 Author Share Posted July 3, 2008 it just stops at this if($image == false){die ('Unable to open image');} i don't see why its not working. i've tried different file types and file sizes and files saved by different programs. it just seems like it only randomly works sometimes. and i've also tried showing the url of the image its trying to open and the image shows up fine. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 You are using the correct file types, right? And you have this line set up with a real url and the correct location? $image = open_image("http://site.com/$open_image_url/$image_name"); Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 If the image won't open as the type that its extension suggests, you could try loading it using the functions for the other types, just in case the extension is wrong. You should probably do some kind of sanity check to see that the URL isn't a 404, unless you're 100% certain it's there. Quote Link to comment Share on other sites More sharing options...
acidglitter Posted July 11, 2008 Author Share Posted July 11, 2008 yea i've tried more than one file type, and i've checked and the url to the image is just fine. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 11, 2008 Share Posted July 11, 2008 please remove the @ it only suppress code and error Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 11, 2008 Share Posted July 11, 2008 also you need a check statement like <?php if($ext=="image/gif"||$ext=="image/png"||$ext=="image/jpeg") { //upload }else { //error }?> Quote Link to comment Share on other sites More sharing options...
acidglitter Posted July 27, 2008 Author Share Posted July 27, 2008 i just checked the permissions on one of the pictures i was trying to resize.. it was set to 644.. could that be why my script can't open it to resize it? Quote Link to comment Share on other sites More sharing options...
acidglitter Posted July 28, 2008 Author Share Posted July 28, 2008 never mind. it turns out the script wasn't the problem. the folder all of the images were in was password protected by an .htaccess file.... 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.