课程名称:PHP进阶篇-GD库图像处理
课程章节:第3章 图像常用操作
主讲老师:king
课程内容:
今天学习的内容包括:
缩略图简单实现
jd缩略图效果及等比例缩放的实现
课程收获:
我的环境是 php 8.19 nts版本
缩略图简单实现流程 jd缩略图效果及等比例缩放的实现
<?php
header('content-type:text/html;charset=utf-8');
ini_set('date.timezone','Asia/Shanghai');
//$filename='images/ipad.png';
$filename='images/ipad.jpg';
//$filename='images/ya.gif';
$fileInfo=getimagesize($filename);
list($src_w,$src_h)=$fileInfo;
//var_dump($fileInfo);
//创建100x100图
$dst_w=100;
$dst_h=100;
//创建目标画布资源
$dst_image=imagecreatetruecolor($dst_w,$dst_h);
//通过图片文件创建画布资源
$src_image=imagecreatefromjpeg($filename);
//var_dump($src_image);exit;
imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
imagejpeg($dst_image,'thumbs/thumb_100x100.jpg');
imagedestroy($src_image);
imagedestroy($dst_image);
<?php
/**
* @Author: Administrator
* @Date: 2022-08-16 08:42:48
* @Last Modified by: Administrator
* @Last Modified time: 2022-08-16 09:06:59
*/
// jd缩略图效果及等比例缩放的实现
header('content-type:text/html;charset=utf-8');
ini_set('date.timezone','Asia/Shanghai');
$filename='images/ipad.png';
//$filename='images/ipad.jpg';
//$filename='images/ya.gif';
$fileInfo=getimagesize($filename);
if($fileInfo){
list($src_w,$src_h)=$fileInfo;
}else{
die('不是真实图片文件!');
}
$src_image=imagecreatefrompng($filename);
//50x50
$dst_image_50=imagecreatetruecolor(50, 50);
//270x270
$dst_image_270=imagecreatetruecolor(270, 270);
imagecopyresampled($dst_image_50, $src_image, 0, 0, 0, 0, 50, 50, $src_w, $src_h);
imagecopyresampled($dst_image_270, $src_image, 0, 0, 0, 0, 270, 270, $src_w, $src_h);
imagepng($dst_image_50,'thumbs/thumb_50x50.png');
imagepng($dst_image_270,'thumbs/thumb_270x270.png');
imagedestroy($dst_image_50);
imagedestroy($dst_image_270);
imagedestroy($src_image);