<?php
/**
* 说明:函数功能是把一个图像裁剪为任意大小的图像,图像不变形
* 参数说明:输入 需要处理图片的 文件名,生成新图片的保存文件名,生成新图片的宽,生成新图片的高
*/
// 获得任意大小图像,不足地方拉伸,不产生变形,不留下空白
function my_image_resize($src_file, $dst_file, $new_width, $new_height)
{
if ($new_width < 1 || $new_height < 1) {
echo 'params width or height error !';
die;
}
if (!file_exists($src_file)) {
echo $src_file . ' is not exists !';
die;
}
// 图像类型
$type = exif_imagetype($src_file);
$support_type = array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF);
if (!in_array($type, $support_type, true)) {
echo 'this type of image does not support! only support jpg , gif or png';
die;
}
//Load image
switch ($type) {
case IMAGETYPE_JPEG:
$src_img = imagecreatefromjpeg($src_file);
break;
case IMAGETYPE_PNG:
$src_img &#
PHP实用图片压缩方法
最新推荐文章于 2023-07-06 16:59:52 发布