Dan911 Posted June 19, 2007 Share Posted June 19, 2007 I have created an image resizing script, and am having trouble saving the resized image to the server. imagejpeg($image_resized, $imagelocation); should save the image to where I designate $imagelocation as, but it doesn't. Should i use fopen instead? Also, is there any way i can make it so this script scan folders and apply the script to certian files in them? And why does my script not work when I say open_image($picture); when picture is defined as $picture = 'flower.jpg' Thanks, Dan <?php //dan's lame image resizer // Load image $image = open_image('flower.jpg'); if ($image === false) { die ('Unable to open image'); } // Get original width and height $width = imagesx($image); $height = imagesy($image); //echo 'Height: ' . imagesy($image) . ' pixels'; //echo 'Width: ' . imagesx($image) . ' pixels'; // Set a new width, and calculate new height $new_width = 200; $new_height = $height * ($new_width/$width); // Resample $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Display resized image $imagelocation = 'resizedflower.jpg' header('Content-Type: image/jpeg'); imagejpeg($image_resized, $imagelocation); die(); function open_image ($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($file); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($file); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56226-picture-saving-after-resize/ 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.