PHP ?? ??? ?? ??
?? ??
<?php /*打開圖片*/ $src = "https://img.php.cn/upload/course/000/000/004/581454f755fb1195.jpg"; $info = getimagesize($src); $type = image_type_to_extension($info[2],false); $fun = "imagecreatefrom{$type}"; $image = $fun($src); /*操作圖片*/ //在內(nèi)存中建立一個寬300高200的真色彩圖片 $image_thumb = imagecreatetruecolor(300,200); //將原圖復(fù)制到新建的真色彩圖片上,并且按照一定比例壓縮(參數(shù)1:真色彩圖片,參數(shù)2:原圖,參數(shù)3,4,5,6:原圖和真色彩圖的起始點(diǎn),參數(shù)7,8:原圖和真色彩圖的結(jié)束點(diǎn),參數(shù)9:原圖寬,參數(shù)10:原圖高) imagecopyresampled($image_thumb,$image,0,0,0,0,300,200,$info[0],$info[1]); //銷毀原始圖片 imagedestroy($image); ?>
?? ??:
?? ???? ??? ??? ?? ???? ????.
imagecreatetruecolor()? ??? ??? ???? ??? ???? ?????. x_size ? y_size? ??? ???.
??? ??? ? imagecopyresampled()
bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
imagecopyresampled()? ? ????? ?? ???? ???? ??? ???? ?? ?? ???? ????? ?? ??? ??? ??? ??? ??? ???? ?????.
dst_image
?? ??? ?? ??????.
src_image
?? ??? ?? ??????.
dst_x
?? X ???.
dst_y
?? Y ???.
src_x
??? X ??????.
src_y
??? Y ??????.
dst_w
?? ??.
dst_h
?? ??.
src_w
?? ???? ?????.
src_h
?? ???? ?????.
??? ???? ??? ???? ?????.