之前用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);
【一】.抽象类假设如下场景:团队准备开发某网站,表建好了,页面设计好了.A组负责开发底层数据库操作类(DB),B组负责调用DB类.但是此时A组发生了争执,MySQL? Oracle? DB2? sqlite?到底使用什么数据库?B组.... 进入漫长的等待.解决方法:A组和B组 先定1个数据库类的模...
第一步:服务端文件<?php $wsdlfile='webservice.wsdl'; ini_set('soap.wsdl_cache_enabled','0'); //关闭WSDL缓存 //001...
如果想在windows中执行php,并且让php脚本在后台运行,可以用下面的cmd命令start /b php D:\wwwroot\default\demo1\run.php例如上面的命令意思后台运行run.php,如果想用php编写异步代码: ...
开发com组件可以用c++,vc++,net,我比较熟悉net,演示用dnet(1).创建项目:启动vs2017,新建项目,选择Visual C# ->Windows桌面->类库通用windows(2). 修改Com项目:点击 项目->项目属性,再点击应用程序->程序集信息,...
使用php函数array_multisort()即可实现和SQL一样的order by排序. 例如我们需要对会员表按照主键降序排列,年龄升序排列://会员表数据 $list = []; $list[] = ['mid' =>&n...
逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event { /** &nbs...