之前用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);
<?PHP $a=0.5*100; if(is_int($a)){ echo'int'; } else{ echo'not int'; } ...
通过http推送消息给socket,socket服务再向客户端推送<?php /* * Socket推送 * 请用守护进程方式启动php msgservice.php & (socket只...
如果想在windows中执行php,并且让php脚本在后台运行,可以用下面的cmd命令start /b php D:\wwwroot\default\demo1\run.php例如上面的命令意思后台运行run.php,如果想用php编写异步代码: ...
重构框架的时候想要考虑支持下cli模式,于是参考了thinkphp的底层。/** * 获取应用根目录 * @return string */ public static function getRootP...
最近在公司开发一个新的项目假设项目域名是a.com,需要接入b.com的单点登陆系统。(1).首先我们会在a.com的登陆页面用iframe引入b.com来显示登陆界面,实际上登陆验证操作都是在b.com上面(2).当b.com验证通过,会在前端ajax请求a.com的回调地址,这个回调地址目的就是...
今天帮朋友查询wordpress执行超级慢的原因,特此记录开启fpm的慢日志,记录执行超过30秒的脚本request_slowlog_timeout = 30 slowlog = var/log/slow.log查看日志[23-May-2019 17...