Nimisha Posted July 27, 2004 Posted July 27, 2004 Hi everyone New to the family here so site isn't working yet. However I'm trying to not stress the server. My site has a bug bundle of photos which at the moment I have setup to do on-the-fly thumbnails. I want to change that so the thumbnail is generated when the upload happens. I thought I had a good script to do that and can create thumbnails for a whole drectory. Handy since I have over 500 pictures already. So I tried to run it to create the thumbnails in the directory......... But I get the following message Warning: imagejpeg(): Unable to open 'tn_016.jpg' for writing blah blah Line 77 etc etc but only through to pics starting with h On the end t says Fatal Error 30 seconds exceeded etc. Oh, I did change the permissions... not sure if I changed them correctly of course.... the script: ><?php $gd2=checkgd(); $pics=directory("/home/{username}/public_html/funnypics/img","jpg,JPG,JPEG,jpeg,png,PNG"); $pics=ditchtn($pics,"tn_"); if ($pics[0]!=""){ foreach ($pics as $p){ createthumb("/home/{username}/public_html/funnypics/img/".$p,"tn_".$p,90,90); } } /* Function checkgd() checks the version of gd, and returns "yes" when it's higher than 2 */ function checkgd(){ $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2'){$gd2="yes";} return $gd2; } /* Function ditchtn($arr,$thumbname) filters out thumbnails */ function ditchtn($arr,$thumbname){ foreach ($arr as $item){ if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;} } return $tmparr; } /* Function createthumb($name,$filename,$new_w,$new_h) creates a resized image variables: $name Original filename $filename Filename of the resized image $new_w width of resized image $new_h height of resized image */ function createthumb($name,$filename,$new_w,$new_h){ global $gd2; $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2==""){ $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); }else{ $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])){ imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } /* Function directory($directory,$filters) reads the content of $directory, takes the files that apply to $filter and returns an array of the filenames. You can specify which files to read, for example $files = directory(".","jpg,gif"); gets all jpg and gif files in this directory. $files = directory(".","all"); gets all files. */ function directory($dir,$filters){ $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} if ($filters != "all"){ $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0;$f<sizeof($filters);$f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } ?> Regards Margo Quote
TCH-Bruce Posted July 27, 2004 Posted July 27, 2004 I would assume that if you are getting an unable to open message that it would be a permissions problem when trying to create the image. Have you set the permissions to the folder to 777 ? Quote
Nimisha Posted July 27, 2004 Author Posted July 27, 2004 AFAIK the directory is 777... glad I got that right There are a few thumbnails in the directory - about 20 not sure if that would cause a problem? Always try the easy thing first. Bruce, you were correct. The thumbs dir was 755. However, the other problem was that the script was timing out. In other words don't try and create over 500 thumbnails in one hit I changed it to do 100 at a time and everything was fine. Updated the upload script and all is working Margo Quote
virtualstijn Posted August 13, 2004 Posted August 13, 2004 I (stijn) set permissions to ALL and still I get the following error: Warning: imagejpeg(): Unable to open 'tn_Ballerina.jpg' for writing in /home/stijnvs/public_html/fons/images.html on line 78 Quote
TCH-Bruce Posted August 13, 2004 Posted August 13, 2004 I (stijn) set permissions to ALL and still I get the following error: Warning: imagejpeg(): Unable to open 'tn_Ballerina.jpg' for writing in /home/stijnvs/public_html/fons/images.html on line 78 Did you change the permissions on the "images" and "fons" folders to 777? You are going two levels down from your root folder. If the "fons" folder does not allow everyone access then the images folder settings are ignored. Quote
virtualstijn Posted August 16, 2004 Posted August 16, 2004 Just put the thumbs in the wrong dir. Anyway... Thanks for all the help Quote
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.