-->
[php] 2023-03-31 圈点727
摘要:php之imagecopyresized()详细用法和示例,imagecopyresized() 函数用于拷贝图像或图像的一部分并调整大小,成功返回 TRUE ,否则返回 FALSE 。
imagecopyresized() 函数用于拷贝图像或图像的一部分并调整大小,成功返回 TRUE ,否则返回 FALSE 。
语法:
bool imagecopyresized( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
本函数参数可参看 imagecopy() 函数,只是本函数增加了两个参数(注意顺序):
dst_w:目标图像的宽度。
dst_h:目标图像的高度。
示例:
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>