sailorsmokey Posted May 18, 2009 Share Posted May 18, 2009 It has been approximately 5 years since I've last even looked at GD library scripts. And I don't remember them - at all. I've got this code going, but I can't figure out why it won't copy the image into the correct folder. I'm going to include the section where it's copying the image - maybe someone will see something in there. And if that all checks out, then I guess I'll keep searching the rest of the code for something that's out of place. Absolutely no errors pop up when I run this code. The folder has 777 permissions. But after I run the code, no image appears in the "additionalpix" folder. $dest="/PrivateInfo/additionalpix/$additionalpix_name"; $size = GetImageSize($additionalpix); $image_types = array( 'image/pjpeg' => '.jpg', 'image/jpeg' => '.jpg', 'image/jpg' => '.jpg', 'image/gif' => '.gif', ); $filetype = $_FILES['additionalpix']['type']; $extension = $image_types[$filetype]; //define size based on tall or wide // Wide Image if($size[0] > $size[1]) { if ($size[0]>250){//only modify it if it's larger $image_width = 250; $image_height = (int)(250 * $size[1] / $size[0]); }else{ $image_width = $size[0]; $image_height = $size[1]; } } // Tall Image else { if($size[1]>175){ $image_width = (int)(175 * $size[0] / $size[1]); $image_height = 175; }else{ $image_width = $size[0]; $image_height = $size[1]; } } $gd_function_suffix = array( '.jpg' => 'JPEG', '.gif' => 'GIF', ); $function_suffix = $gd_function_suffix[$extension]; $function_to_read = 'ImageCreateFrom'.$function_suffix; $function_to_write = 'Image' . $function_suffix; // Read the source file $source_handle = $function_to_read($additionalpix); if ($source_handle) { // Let's create a blank image $destination_handle = ImageCreateTrueColor($image_width, $image_height); // Now we resize it ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $image_width, $image_height, $size[0], $size[1]); } // Let's save $function_to_write($destination_handle, $dest); Quote Link to comment Share on other sites More sharing options...
Brian W Posted May 18, 2009 Share Posted May 18, 2009 You don't get any errors? do you have error_reporting(E_ALL) on for testing? $function_to_write($destination_handle, $dest); That throws up a flag with me at least when I read through it. Quote Link to comment Share on other sites More sharing options...
sailorsmokey Posted May 19, 2009 Author Share Posted May 19, 2009 No, I didn't have the function error_reporting(E_ALL) on, but I just turned it on and ran it. Again, no error pops up. And I thought I had the $function_to_write set up correctly, but by your above post, I get the hint that I don't, but I don't know what I did wrong. I have some examples in other areas of the Web site, and it looks correct compared to them. If you're feeling generous out there, pass me another hint, and I'll keep digging on this. Thanks! Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 19, 2009 Share Posted May 19, 2009 yeah, that $function_to_write thing doesn't look right - and I can't locate a function named function_to_write. There are several functions for saving images. Looks like you're using jpegs and gifs. The relative functions are imagejpeg() and imagegif(). http://php.net/imagejpeg http://php.net/imagegif Quote Link to comment Share on other sites More sharing options...
sailorsmokey Posted May 21, 2009 Author Share Posted May 21, 2009 I think that function_to_write thing is part of the GD library, but I'm having trouble piecing this whole thing together. Here's a tutorial I found on resizing thumbnails with the GD library that uses function_to_write: http://www.sitepoint.com/article/php-gallery-system-minutes/5/ If anyone has any further input on this, I'd love to fix what I already have, but if no one has any other suggestions, I will go with Michael's suggestion of using imagejpeg(). I was just hoping not to have to start over, but again, will do what I have to. Thank you! Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 21, 2009 Share Posted May 21, 2009 I wrote this a few years back - still use it for resizing images: <?php ini_set("memory_limit","128M"); //optional - I find it useful if you're expecting really big files to be uploaded function resize_image($func_im,$width,$height) { if(imagesx($func_im)>imagesy($func_im)) { if(imagesx($func_im)<=$width) { $func_newim=imagecreatetruecolor(imagesx($func_im),imagesy($func_im)); imagecopy($func_newim,$func_im,0,0,0,0,imagesx($func_im),imagesy($func_im)); } else { $func_newim=imagecreatetruecolor($width,((imagesy($func_im)/imagesx($func_im))*$width)); imagecopyresampled($func_newim,$func_im,0,0,0,0,$width,((imagesy($func_im)/imagesx($func_im))*$width),imagesx($func_im),imagesy($func_im)); } } else { if(imagesy($func_im)<=$height) { $func_newim=imagecreatetruecolor(imagesx($func_im),imagesy($func_im)); imagecopy($func_newim,$func_im,0,0,0,0,imagesx($func_im),imagesy($func_im)); } else { $func_newim=imagecreatetruecolor(((imagesx($func_im)/imagesy($func_im))*$height),$height); imagecopyresampled($func_newim,$func_im,0,0,0,0,((imagesx($func_im)/imagesy($func_im))*$height),$height,imagesx($func_im),imagesy($func_im)); } } return($func_newim); } //function ends - here's how I call it: do { if((key($_FILES)!="") AND (strlen(file_get_contents($_FILES[key($_FILES)]['tmp_name'])))) { $im=imagecreatefromstring(file_get_contents($_FILES[key($_FILES)]['tmp_name'])); $newim=resize_image($im,300,240); $thumb=resize_image($im,75,75); imagejpeg($thumb,"/full/path/to/file/".$_FILES[key($_FILES)]['name'],90); imagejpeg($newim,"/full/path/to/file/".$_FILES[key($_FILES)]['tmp_name'],90); } }while(each($_FILES)); ?> Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted May 21, 2009 Share Posted May 21, 2009 sorry, that $newim line should have 'name' instead of 'tmp_name' 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.