【问题标题】:merge images with text将图像与文本合并
【发布时间】:2010-10-17 07:27:07
【问题描述】:

有没有办法将文本放在 png 上,然后将其与 jpg / gif 图像合并?

【问题讨论】:

  • 你能详细说明你的问题吗?将 png 与 jpg/gif 图像合并是什么意思?

标签: php image merge gd


【解决方案1】:

您可以使用 ttf 或 type1 字体使用 gd 在图像中或图像上绘制任何文本(如果它在 php 中的 gd 中启用)。

http://hr.php.net/manual/en/image.examples-watermark.php

【讨论】:

    【解决方案2】:

    您没有说您使用的是什么语言,但Imagemagick 有几种不同语言的 API (http://www.imagemagick.org/script/api.php)。

    【讨论】:

      【解决方案3】:

      这就是我的做法。

      /* load the image */
      $im = imagecreatefrompng("image.png");
      
      /* black for the text */
      $black = imagecolorallocate($im, 0, 0, 0);
      
      /* put the text on the image */
      imagettftext($im, 12, 0, 0, 0, $black, "arial.ttf", "Hello World");
      
      /* load the jpg */
      $jpeg = imagecreatefromjpeg("image.jpeg");
      
      /* put the png onto the jpeg */
      /* you can get the height and width with getimagesize() */
      imagecopyresampled($jpeg,$im, 0, 0, 0, 0, $jpeg_width, $jpeg_height, $im_width, $im_height);
      
      /* save the image */
      imagejpeg($jpeg, "result.jpeg", 100);
      

      不过,这是一个非常简单的例子。

      【讨论】:

        猜你喜欢
        • 2014-05-08
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 2021-12-11
        • 2018-12-21
        • 2016-07-25
        • 1970-01-01
        相关资源
        最近更新 更多