调整图像大小并用颜色填充比例间隙
我正在将徽标上传到我的系统,它们需要修复在 60x60 像素框中。我有所有代码可以按比例调整它的大小,这不是问题。
我的 454x292px 图像变成了 60x38。问题是,我需要图片为 60x60,这意味着我想用白色填充顶部和底部(我可以用颜色填充矩形)。
理论上是我创建一个白色矩形,60x60,然后复制图像并将其大小调整为 60x38,并将其放入我的白色矩形中,从顶部开始 11 像素(这加起来就是我需要的总填充的 22 像素。
我会发布我的代码,但它很长,但如果需要的话我可以。
有谁知道如何做到这一点,或者你能给我指出执行此操作的代码/教程吗?
I am uploading logos to my system, and they need to fix in a 60x60 pixel box. I have all the code to resize it proportionately, and that's not a problem.
My 454x292px image becomes 60x38. The thing is, I need the picture to be 60x60, meaning I want to pad the top and bottom with white each (I can fill the rectangle with the color).
The theory is I create a white rectangle, 60x60, then I copy the image and resize it to 60x38 and put it in my white rectangle, starting 11px from the top (which adds up to the 22px of total padding that I need.
I would post my code but it's decently long, though I can if requested.
Does anyone know how to do this or can you point me to code/tutorial that does this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与GD:
With GD:
http://php.net/manual/en/function.imagecopyresampled.php
这基本上就是您想要平滑复制并调整其大小的功能。
http://www.php.net/manual/en/function.imagecreatetruecolor。 php
用它创建一个新的黑色图像。
http://www.php.net/manual/en/function.imagefill。 php
那部分解释了如何将其填充为白色。
其余的如下。
http://php.net/manual/en/function.imagecopyresampled.php
That's basically the function you want to copy and resize it smoothly.
http://www.php.net/manual/en/function.imagecreatetruecolor.php
With that one you create a new black image.
http://www.php.net/manual/en/function.imagefill.php
That part explains how to fill it white.
The rest follows.