Home > Backend Development > PHP Tutorial > php gd 搴搴搴暱鏁扮敓镣愰佩搴捉鐣ュ浘绋嫔簭_PHP鏁欑▼ | 搴涔嫔

php gd 搴搴搴暱鏁扮敓镣愰佩搴捉鐣ュ浘绋嫔簭_PHP鏁欑▼ | 搴涔嫔

WBOY
Release: 2016-07-13 10:45:56
Original
1249 people have browsed it

gd搴洴槸php鏁欑▼涓竴涓鐞嗗浘镕殑涓撶敤搴掳纴浠栧彲浠ユ南渚揩掹风殑澶勭悊澶у鏁版偁澶勭把攛屽畠愻淪緵浜嗗ぇread忕殑锲 drama喾澶拭悊鍑 Mustard暟锛屼笅闱㈡垜浠amine鍒╃敤gd搴撶殑鍑mustard What’s the point?br /> 雪嬭瘯浠g爜

include('resizeimage.php');
if(!empty($_post)){
echo($filename.".jpg?cache=".rand(0,999999));
}
?>



resizeimage.php 邂囦浩

$filename="image.thumb";
// 鐢縸帚锲综合墖镄啫搴?
$resizewidth=400;
// 鐢縸帚锲综合墖锄勯珮搴?
$resizeheight=400;

function resizeimage($im,$maxwidth,$maxheight,$name){
$width = imagesx($im);
$height = imagesy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$resizewidth=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$resizeheight=true;
}
if($resizewidth && $resizeheight){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($resizewidth){
$ratio = $widthratio;
}elseif($resizeheight){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
imagejpeg ($newim,$name . ".jpg");
imagedestroy ($newim);
}else{
imagejpeg ($im,$name . ".jpg");
}
}

if($_files['image']['size']){
if($_files['image']['type'] == "image/pjpeg"){
$im = imagecreatefromjpeg($_files['image']['tmp_name']);
}elseif($_files['image']['type'] == "image/x-png"){
$im = imagecreatefrompng($_files['image']['tmp_name']);
}elseif($_files['image']['type'] == "image/gif"){
$im = imagecreatefromgif($_files['image']['tmp_name']);
}
if($im){
if(file_exists("$filename.jpg")){
unlink("$filename.jpg");
}
resizeimage($im,$resizewidth,$resizeheight,$filename);
imagedestroy ($im);
}
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632985.htmlTechArticlegd搴洴槸php鏁欑▼涓竴涓鐞嗗浘镕殑涓涶敤搴掳纴浠栧姲浠ユ南渚揩掹风殑澶拭悊澶у鏁版偁澶拊攛屽畠鎻愪緵浜嗗ぇRead啕殑锲 drama 墖澶拭捌捑mustard闱㈡垜浠Ammonium鍒╃敤gd搴撶捑鍑 Mustard隟鏉?..
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template