之前用ceomax的wordpress主题发现它的缩略图很好看,于是其他项目也是参考它的来生成图片。
背景图如下:
原图如下:
生成效果图:
参考代码:
// 使用示例 $originalImagePath = './944b687112.png'; $backgroundImagePath = './ceo_img_1.png'; $thumbnailWidth = 200; $thumbnailHeight = 200; $thumbnailQuality = 75; // 加载图像 $background = imagecreatefrompng($backgroundImagePath); $foreground = imagecreatefrompng($originalImagePath); // 获取图像尺寸 $backgroundWidth = imagesx($background); $backgroundHeight = imagesy($background); $foregroundOriginalWidth = imagesx($foreground); $foregroundOriginalHeight = imagesy($foreground); // 计算缩放比例 $scaleX = $backgroundWidth / $foregroundOriginalWidth; $scaleY = $backgroundHeight / $foregroundOriginalHeight; $scale = min($scaleX, $scaleY); // 选择较小的比例以保证图像完全适应背景 // 计算缩放后的尺寸 $foregroundWidth = 282; $foregroundHeight = 166; // 创建一个新图像,大小与背景图像相同 $newImage = imagecreatetruecolor($backgroundWidth, $backgroundHeight); // 复制背景图像到新图像 imagecopy($newImage, $background, 0, 0, 0, 0, $backgroundWidth, $backgroundHeight); // 计算前景图像在新图像中的位置(这里居中) $x = 59; $y = 56; // 使用imagecopyresampled缩放并复制前景图像到新图像 imagecopyresampled($newImage, $foreground, $x, $y, 0, 0, $foregroundWidth, $foregroundHeight, $foregroundOriginalWidth, $foregroundOriginalHeight); // 保存新图像 imagejpeg($newImage, 'new_image.jpg', 100); // 90是质量参数,范围从0到100 // 释放资源 imagedestroy($background); imagedestroy($foreground); imagedestroy($newImage);
先在centos安装openssl,然后开始://生成私钥openssl genrsa -out rsa_private_key.pem 1024//生成公钥openssl rsa -in rsa_private_key.pem&...
第一步:服务端文件<?php $wsdlfile='webservice.wsdl'; ini_set('soap.wsdl_cache_enabled','0'); //关闭WSDL缓存 //001...
上篇文章已经讲解arrayacces的原理,现在来讲解下arrayaccess的实际应用。一个大型的互联网项目中必然会存在各种配置信息,例如多种数据库信息:mysql,tidb,mongodb,redis,某个业务模块单独的配置信息如比例,额度等等,那么该如何治理配置信息?PHP项目中大部分的框架都...
面试中PHP面试官会问调用一个不存在的方法,如何知道是哪个文件哪行调用的?假设方法是getWorkLoad()回答1:开启PHP错误输出,PHP会输出Fatal error: Call to undefined function getWorkLoad() in D:\wwwroot\thinkpa...
(1).学习目标: 了解常见信号类型(百度PHP支持的信号类型),(2).相关函数学习: (2.1).pcntl_signal函数用于设置一个信号管理器接收进程信号,参数1:信号类型,参数2:回调函数,用于在接收到参数1类型的信...
php7新增的特性(1).强制限制只能返回一种类型<?php class task { } //must return an integer function add(): int { &nb...