php 通过 imagecopyresampled 用于剪切出一个新的图片

使用到的函数:

imagecreatefromjpeg(); 通过打开一个图像得到这个图像的 img resource

imagecreatetruecolor(); 创建一个真彩色的图像

imagecopyresampled(); 从原图片复制剪切出一个新的图片并放在通过 imagecreatetruecolor() 创建的图像中

效果图:

代码:

<?php
// PHP 使用 GD 拓展库制作图像
// 指定输出为 JPEG 图片
header('Content-type:image/jpeg');
// imagecreatefromjpeg('文件名') 得到源文件
$img_resource = imagecreatefromjpeg('2019-10-26.jpg');
// 1、创建图像
$img_target = imagecreatetruecolor(500, 500);
// 2、从原图片复制一个新的图片出来
imagecopyresampled($img_target, $img_resource, 100, 100, 0, 0, 200, 200, 200, 200);
// 3、输出图像
imagejpeg($img_target);
// 4、释放资源
imagedestroy($img_resource);
imagedestroy($img_target);

猜你喜欢

转载自www.cnblogs.com/GetcharZp/p/12262689.html