note 63767 added to function.imagecopyresized
| From: | muoihv at gmail dot com | Date: | Thu, 30 Mar 2006 09:36:54 +0000 |
| Subject: | note 63767 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107003@lists.php.net to get a copy of this message | ||
From : www.sangtaoco.com www.giaphaptructuyen.net
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<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>
<?
$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" ;
?>
<?
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);
}
?>
</body>
</html>
----
Server IP: 66.163.161.117
Probable Submitter: 203.162.3.160 (proxied: 222.253.132.103)
----
X-Spam-Status: No, hits=4.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_40_50,HTML_MESSAGE,HTML_TAG_BALANCE_HTML autolearn=no
version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/note/edit/63767
Del: integrated -- http://master.php.net/note/delete/63767/integrated
Del: useless -- http://master.php.net/note/delete/63767/useless
Del: bad code -- http://master.php.net/note/delete/63767/bad+code
Del: spam -- http://master.php.net/note/delete/63767/spam
Del: non-english -- http://master.php.net/note/delete/63767/non-english
Del: in docs -- http://master.php.net/note/delete/63767/in+docs
Del: other reasons-- http://master.php.net/note/delete/63767
Reject -- http://master.php.net/note/reject/63767
Search -- http://master.php.net/manage/user-notes.php