note 63766 deleted from function.imagecopyresized by nlopess

From: Date: Thu, 30 Mar 2006 10:07:56 +0000
Subject: note 63766 deleted from function.imagecopyresized by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107006@lists.php.net to get a copy of this message
Note Submitter: sangtaoco at yahoo dot com ( muoihv Vietnamese) ---- /* Viet Nam Viet deu chinh kich thuoc 1 image cho phu hop, rat kho, va ham imagejpeg nhat dinh khong chay, toi khong biet lam sao, nen danh dung ke " di duong vong" cach tot nhat la chuyen het ve 1 dinh dang jpg */ -> You can change all with type JPG // From nhap lieu - Input data <form name="form1" enctype="multipart/form-data" method="post" action="125.php"> <input type="file" name="filen"> <input type="submit" name="Submit" value="Submit"> </form> // After funtion conversion with from gif, png -> to jpg or JPEG <? $filename = $_FILES['filen']['name']; $filetuyoevn = $_FILES['filen']['type'];//echo '<br>$filetuyoevn:'.$filetuyoevn; $filename = strtolower($filename); echo '<br>$filename:'.$filename; ?> <p><?=$filejpg;?> <img src="<?=$filename;?>" ></p> <? list($width, $height) = @getimagesize($filename); echo '$width: '.$width; $newwidth = 120; if($width > $newwidth) { if(preg_match("/.gif/i", "$filename") || preg_match("/.png/i", "$filename")) { $name = substr($filename,0,strlen($filename)-4);// echo '<br> $name:'. $name; $filejpg = $name.".jpg";// echo '<br> $filename:'. $filename; ConverToJPG($filename , $filejpg); print 'gif | png| <img src="'.$filename .'"><br>'; resizeImageJPG($filejpg, $newwidth ); $filename = $filejpg; } else if( preg_match("/.jpg/i", "$filename") ) { print 'jpg <img src="'.$filename .'"><br>'; resizeImageJPG($filename,$newwidth ); } else echo "anh nay khong hop le"; echo $filename.'<img src="'.$filename.'">'; } // if else if ($width > 0) { echo 'KHong resize : <img src="'.$filename.'">'; } else echo "Ban chuan nhap anh" ; ?> // Sau do ban xay dung ham deu chinh kich thuoc theo y muon voi dinh dang JPG //change rezise image JPG <? function ConverToJPG($src, $dest) //SkewJPG($src, $dest, $skew_val) { $imgsrc = imagecreatefromgif($src); $width = imagesx($imgsrc); $height = imagesy($imgsrc); $imgdest = imagecreatetruecolor($width, $height);// $imgdest = imagecreatetruecolor($width, $height+($height*$skew_val)); $trans = imagecolorallocate($imgdest,0,0,0); $temp=0; for($x=0 ; $x<$width ; $x++) { for($y=0 ; $y<$height ; $y++) { imagecopy($imgdest, $imgsrc, $x, $y+$temp, $x, $y, 1, 1); imagecolortransparent($imgdest,$trans); } $temp+=$skew_val; } imagejpeg($imgdest, $dest); imagedestroy($imgsrc); imagedestroy($imgdest); } function resizeImageJPG($cur_file, $newwidth) //resizeImageJPG($cur_file, $newwidth,$newheight ) { $dir_name = $cur_dir; $olddir = getcwd(); $dir = opendir($dir_name); // set width, height $filename = $cur_file; $format=''; if(preg_match("/.jpg/i", "$filename")) { $format = 'image/jpeg'; } if(preg_match("/.jpeg/i", "$filename")) { $format = 'image/jpeg'; } $source = imagecreatefromjpeg($filename); list($width, $height) = @getimagesize($filename); (int)$imgratio = $width / $height; //echo '<br>$imgratio:'.$imgratio; if ($imgratio>1){ // echo "<br> Ngang > Cao"; (int)$newheight = ($height*$newwidth )/$width ; //echo '$width:'.$width .'|$height:'.$height; //echo '$newheight:'.$newheight.'|$newwidth:'.$newwidth; } else { //echo "<br> Ngang < Cao"; $temH = $width - $newwidth; (int)$newheight = ($height - $temH)*$imgratio ;// (int)$imgW = $height / $width; (int)$newheight = ($height - $temH)*$imgW ; //echo "<br>else"; echo ' $temH :'. $temH; echo ' $temH :'. $temH; echo '$width:'.$width .'|$height:'.$height; //echo '$newheight:'.$newheight.'|$newwidth:'.$newwidth; } $thumb = imagecreatetruecolor($newwidth,$newheight); imagealphablending($thumb, false); $source = imagecreatefromjpeg($filename); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); if(preg_match("/.jpg/i", $filename)){ imagejpeg($thumb, $filename,100); } if(preg_match("/.jpeg/i", $filename)){ imagejpeg($thumb, $filename,100); } imagedestroy($thumb); } ?> // thank

« previous php.notes (#107006) next »