note 54930 added to function.imagecopyresampled

From: Date: Tue, 19 Jul 2005 22:27:37 +0000
Subject: note 54930 added to function.imagecopyresampled
Groups: php.notes 
Request: Send a blank email to php-notes+get-92189@lists.php.net to get a copy of this message
<?php function img_resize($path,$w=0,$h=0,$quality=100,$save=''){ $image_data=@getimagesize($path); $image_type=$image_data[2]; $gd_ext=array('','jpg','gif'); if($image_type!=1&&$image_type!=2) return false; if($save=='') header('Content-type: '.$image_data['mime']); else $save=eregi_replace('%ext',$gd_ext[$image_type],$save); if($w!=0){ $rapporto=$image_data[0]/$w; if($h!=0){ if($image_data[1]/$rapporto>$h) $rapporto=$image_data[1]/$h; } }elseif($h!=0){ $tmp_h=$image_data[1]/$h; }else{ return false; } $thumb_w=$image_data[0]/$rapporto; $thumb_h=$image_data[1]/$rapporto; if($image_type==1) $img_src=@imagecreatefromgif($path); elseif($image_type==2) $img_src=@imagecreatefromjpeg($path); $img_thumb=@imagecreatetruecolor($thumb_w,$thumb_h); $result=@imagecopyresampled($img_thumb,$img_src, 0,0,0,0,$thumb_w,$thumb_h,$image_data[0],$image_data[1]); if(!$img_src||!$img_thumb||!$result) return false; if($image_type==1) $result=@imagegif($img_thumb,$save); elseif($image_type==2) $result=@imagejpeg($img_thumb,$save,$quality); return $result; } ?> This script resize images. It can also make thumbs. It use the resample of images for hight quality result. It can show the result or save it (if $save isn't null). It respect the width and/or the height of image. It can replace the destination file extestion dinamically (filename.%ext) Support gif & jpg. Return false if something goes wrong. ---- Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54930 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54930&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54930&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92189) next »