Accurax Posted February 26, 2007 Share Posted February 26, 2007 Ok guys... this is a bit annoying (for me at least), so any input is really appreciated. Quite simply im trying to save two copies of an uploaded file to my server, one at full size, and one at a specified thumbnail size. Im having problems getting the thumbnail created on the fly. Heres where im up to so far : <?php //create and save the thumbnail version of this picture. // Load image $image = open_image('*****need to get a path to my pic dir & the variable carrying the file name in here*****); 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 = 100; $new_height = 100; // 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 header('Content-type: image/jpeg'); imagejpeg($image_resized); die(); ?> Now, when i ad a static path to the open_image() function it works and i get a display of te reduced image. However, whenever i try to add any kind of file path that contains a variable..... in order to allow me to create thumbnails for different users ****note: Im renaming all uploaded files to the users "username" as this is unique***** heres my function file for open_image(): <?php 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; } ?> Id really appreciate any help with this .............. it seems to be that the script wont allow me to enter a variable as part of the path to the file i want resizing, and i dont know why. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 26, 2007 Share Posted February 26, 2007 Take the error surpressing off and you might see why. php.net/@ Quote Link to comment Share on other sites More sharing options...
Accurax Posted February 26, 2007 Author Share Posted February 26, 2007 Thanks jessi..... managed to work through it now........ feel a bit thick tbh 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.