多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開(kāi)源 > php教程 > PHP 對(duì) png 圖像進(jìn)行縮放,支持透明背景

PHP 對(duì) png 圖像進(jìn)行縮放,支持透明背景

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-05-18 07:14:43 閱讀次數(shù):3135次

PHP 對(duì) png 圖像進(jìn)行縮放,支持透明背景

function smart_resize_image( $file, $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = true, $use_linux_commands = false )
{
if ( $height <= 0 && $width <= 0 ) {
return false;
}
$info = getimagesize($file);
$image = '';

$final_width = 0;
$final_height = 0;
list($width_old, $height_old) = $info;

if ($proportional) {
if ($width == 0) $factor = $height/$height_old;
elseif ($height == 0) $factor = $width/$width_old;
else $factor = min ( $width / $width_old, $height / $height_old);
$final_width = round ($width_old * $factor);
$final_height = round ($height_old * $factor);

}
else {
$final_width = ( $width <= 0 ) ? $width_old : $width;
$final_height = ( $height <= 0 ) ? $height_old : $height;
}

switch ($info[2] ) {
case IMAGETYPE_GIF:
$image = imagecreatefromgif($file);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($file);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($file);
break;
default:
return false;
}

$image_resized = imagecreatetruecolor( $final_width, $final_height );

if ( ($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG) ) {
$trnprt_indx = imagecolortransparent($image);
// If we have a specific transparent color
if ($trnprt_indx >= 0) {
// Get the original image's transparent color's RGB values
$trnprt_color = imagecolorsforindex($image, $trnprt_indx);
// Allocate the same color in the new image resource
$trnprt_indx = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
// Completely fill the background of the new image with allocated color.
imagefill($image_resized, 0, 0, $trnprt_indx);
// Set the background color for new image to transparent
imagecolortransparent($image_resized, $trnprt_indx);
}
// Always make a transparent background color for PNGs that don't have one allocated already
elseif ($info[2] == IMAGETYPE_PNG) {
// Turn off transparency blending (temporarily)
imagealphablending($image_resized, false);
// Create a new transparent color for image
$color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);

// Completely fill the background of the new image with allocated color.
imagefill($image_resized, 0, 0, $color);

// Restore transparency blending
imagesavealpha($image_resized, true);
}
}

imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);

if ( $delete_original ) {
if ( $use_linux_commands )
exec('rm '.$file);
else
@unlink($file);
}

switch ( strtolower($output) ) {
case 'browser':
$mime = image_type_to_mime_type($info[2]);
header("Content-type: $mime");
$output = NULL;
break;
case 'file':
$output = $file;
break;
case 'return':
return $image_resized;
break;
default:
break;
}

switch ($info[2] ) {
case IMAGETYPE_GIF:
imagegif($image_resized, $output);
break;
case IMAGETYPE_JPEG:
imagejpeg($image_resized, $output);
break;
case IMAGETYPE_PNG:
imagepng($image_resized, $output);
break;
default:
return false;
}

return true;
}
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
為碼而活
積分:4237
15粉絲
7關(guān)注
欄目熱點(diǎn)
關(guān)閉
程序員人生
主站蜘蛛池模板: 午夜dj免费视频观看社区 | 国产不卡视频一区二区在线观看 | 最近最新视频中文字幕4 | 视色在线 | 国产精品国产三级国产专区5o | 国产成人精品综合久久久 | h亚洲| 国产清纯91天堂在线观看 | 中文字幕在线观看免费视频 | 欧美成人性视频播放 | 色综合欧美亚洲另类久久 | 毛片资源站 | 羞羞动漫在线看 | 香蕉视频在线网址 | aa级黄色大片 | 亚洲在线h | 日韩手机在线免费视频 | 尤物精品在线观看 | 欧美成人观看免费全部完小说 | 日韩特黄特色大片免费视频 | 一级做a级爰片性色毛片视频 | 亚洲精品国产福利在线观看 | 交video| 手机看片日韩日韩国产在线看 | 高清不卡一区二区三区 | 看看黄色一级片 | 欧美日韩一区二区三区四区 | 国产精品免费观看 | 久久精品亚洲一区二区 | 欧美黄区 | 午夜亚洲一区二区福利 | 亚洲美女又黄又爽在线观看 | 性欧洲女人18 | 亚洲午夜伦理 | 欧美性xxxx极品高清 | 欧美jizzhd欧美精品巨大 | 亚洲无限乱码一二三四区 | 纯欧美一级毛片免费 | 国产高清在线播放免费观看 | 欧美日本高清动作片www网站 | 成人社区网站 |