首页 技术 正文
技术 2022年11月16日
0 收藏 573 点赞 3,418 浏览 1630 个字
/**
* 功能说明
* 将files/model_24/images/下的所有图片文件进行等比例缩放 到$image40w 尺寸 然后放到files/model_24/model.png图片的指定位置后保存到files/model_24/after/下
*/
function model_24()
{
//要求 货物图片大小为567x567
$path = "files/model_24/";
//得到该目录下面的所有文件
$file=scandir($path."images/");
foreach ($file as $index => $fileName)
{
//如果是文件夹则不继续执行
if(trim(str_replace(".", "", $fileName)) == '')continue;
//得到模板底图图片文件A
$model = imagecreatefrompng($path."model.png");
list($modelWidth,$modelHeight) = getimagesize($path."model.png");
//得到需要放到底图上的图片B
$productImage = file_get_contents($path."images/".$fileName);
$productImage = imagecreatefromstring($productImage);
list($productImageWidth,$productImageHeight) = getimagesize($path."images/".$fileName); //定义一个空白图片 也就是对图片B进行缩放
$image40w = 45;//缩放后的尺寸
$image40h = 45;
$image40 = imagecreatetruecolor($image40w, $image40h);
$white = imagecolorallocate($image40, 255, 255, 255);
imagefill($image40, 0, 0, $white); $productImageHeightRsize = 0;
$productImageWidthRsize = 0;
//如果货物的宽度大于高度 那么宽度定死为$image40size 否则就是高度定死$image40size
if($productImageWidth > $productImageHeight)
{
$scale = $image40w / $productImageWidth;
$productImageHeightRsize = $scale * $productImageHeight;
$productImageWidthRsize = $image40w;
}
else
{
$scale = $image40h / $productImageHeight;
$productImageWidthRsize = $scale * $productImageWidth;
$productImageHeightRsize = $image40h;
}
//定义货物图片坐标 以便左右与上下居中
$x = ($image40w - $productImageWidthRsize) / 2;
$y = ($image40h - $productImageHeightRsize) / 2;
//将商品图片进行缩放
imagecopyresized($image40, $productImage, $x, $y, 0, 0, $productImageWidthRsize, $productImageHeightRsize,$productImageWidth,$productImageHeight);
imagecopymerge($model, $image40, 16, 552, 0, 0, $image40w, $image40h, 100);
imagepng($model,$path."after/".$fileName);
}
echo "model_24()结束<br/>";
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731