在 PHP GD 中调整 png 大小时将 jpg 与 png 合并(水印)

发布于 2024-09-08 23:27:49 字数 715 浏览 6 评论 0 原文

我确信我可以以某种方式解决这个问题,但这花了我太长时间,因为我不是 PHP 人员。希望有人可以在几分钟内为我设置脚本...

所以这就是我需要做的:
我将 2 张图片从智能手机传输到网络服务器。这两个图像需要合并(加水印)。它们略有不同:

  1. 图片是 2 兆像素的 jpg(持有照片)
  2. 图片是 480x800 像素的 png,具有透明背景(持有简单的手指绘画)

现在我需要合并这些图像。第二个 (png) 需要缩放到第一个 (jpeg) 的分辨率。

请注意两件事:

  1. 我只能使用服务器上安装的 GD 库。 Imagick 或类似的工具不可用
  2. 我很清楚第二张图像的质量不会很好。没关系。

那么有人可以帮我解决这个问题吗?就像我说的,我一直在摆弄几个 GD 函数,但进展太慢了。我想我找到了所需的功能 imagecopy水印。但我找不到将它们组合在一起的正确方法。

预先感谢,
员工

谢谢一百万

I am sure I could somehow figure this out but it's just taking me way too long since I am not a PHP guy. Hopefully someone can set up the script for me in minutes...

So here's what I need to do:
I transmit 2 pictures from a smartphone to a webserver. These 2 images need to be merged (watermarked). They differ a little:

  1. picture is a 2 megapixel jpg (holding a photo)
  2. picture will be a png of 480x800 pixels with a transparent background (holding a simple finger painting)

Now I need to merge these images. The 2nd one (png) needs to be scaled to the 1st one's (jpeg) resolution.

Please note 2 things:

  1. I can only use the GD library that is installed on the server. Imagick or alike is not available
  2. I am well aware of the fact that the 2nd image's quality won't be brilliant. That's okay.

So could anyone help me out on this? Like I said, I've been messing around with a couple of GD functions but progress is far too slow. I guess I found the required functions with imagecopy and watermark. But I don't find the right way to put 'em together.

Thanks in advance,
steff

Thanks a million

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2024-09-15 23:27:49

几个月前,我发布了一个执行此操作的函数,由于代码相当大,我将链接我的帖子,查看一下 此处。确保您不要立即执行此操作,它会使您的服务器超载,保存带水印的图像或至少缓存它们。

如果您还需要调整原始或水印的大小,我还发布了一个函数来执行此操作 此处

A few months ago i posted a function that does that, since the code is quite big i will just link my post, check it out here. Make sure you don't do this onfly, it will overload your server, save the watermarked images or at least cache them.

If you also need to resize the original or watermark, i also posted a function to do this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文