note 63766 added to function.imagecopyresized
| From: | (muoihvVietnamese) | Date: | Thu, 30 Mar 2006 09:35:16 +0000 |
| Subject: | note 63766 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107002@lists.php.net to get a copy of this message | ||
/* 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
----
Server IP: 66.163.161.117
Probable Submitter: 203.162.3.160 (proxied: 222.253.132.103)
----
X-Spam-Status: No, hits=4.2 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_40_50,HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/note/edit/63766
Del: integrated -- http://master.php.net/note/delete/63766/integrated
Del: useless -- http://master.php.net/note/delete/63766/useless
Del: bad code -- http://master.php.net/note/delete/63766/bad+code
Del: spam -- http://master.php.net/note/delete/63766/spam
Del: non-english -- http://master.php.net/note/delete/63766/non-english
Del: in docs -- http://master.php.net/note/delete/63766/in+docs
Del: other reasons-- http://master.php.net/note/delete/63766
Reject -- http://master.php.net/note/reject/63766
Search -- http://master.php.net/manage/user-notes.php