note 52939 added to function.imagecopyresized

From: Date: Wed, 18 May 2005 11:45:15 +0000
Subject: note 52939 added to function.imagecopyresized
Groups: php.notes 
Request: Send a blank email to php-notes+get-89578@lists.php.net to get a copy of this message
I was searching for script, that do not resize on the fly, but copy resized file to other place, so after long searches, i've done this function. I hope it will be usefull for someone: (This is not original code, i'v taked it from somwhere and edited a ltl :) <?php function resize($cur_dir, $cur_file, $newwidth, $output_dir) { $dir_name = $cur_dir; $olddir = getcwd(); $dir = opendir($dir_name); $filename = $cur_file; $format=''; if(preg_match("/.jpg/i", "$filename")) { $format = 'image/jpeg'; } if (preg_match("/.gif/i", "$filename")) { $format = 'image/gif'; } if(preg_match("/.png/i", "$filename")) { $format = 'image/png'; } if($format!='') { list($width, $height) = getimagesize($filename); $newheight=$height*$newwidth/$width; switch($format) { case 'image/jpeg': $source = imagecreatefromjpeg($filename); break; case 'image/gif'; $source = imagecreatefromgif($filename); break; case 'image/png': $source = imagecreatefrompng($filename); break; } $thumb = imagecreatetruecolor($newwidth,$newheight); imagealphablending($thumb, false); $source = @imagecreatefromjpeg("$filename"); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $filename="$output_dir/$filename"; @imagejpeg($thumb, $filename); } } ?> call this function using <? resize("./input folder", "picture_file_name", "width", "./output folder"); ?> ---- Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52939 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52939&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52939&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52939&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52939&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52939&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52939&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89578) next »