dongwei9771 2013-11-13 01:26
浏览 17
已采纳

水印压缩图像

I currently use the following code to watermark images on-the-fly and display them in a web page:

header('Content-type: image/jpeg');
$stamp = imagecreatefrompng(watermark.png');
$im = imagecreatefromjpeg($filename);
imagecopy($im, $stamp, 10, imagesy($im) - imagesy($stamp) - 10, 0, 0, imagesx($stamp), imagesy($stamp));
imagejpeg($im);
imagedestroy($im);

I also have a lot of images that are stored in zip archives. I currently display them with the following code.

  $zip = new ZipArchive();
  $opened = $zip->open($zipname, ZIPARCHIVE::CHECKCONS);
  if ( $opened === true ){
    $content = $zip->getFromName($filename);
      header('Content-type: image/jpeg');
      echo $content;
    };  
    $zip->close();

I want to watermark them as well but cannot seem to get it to work. As an initial test I tried changing to output of $content from an echo to:

imagejpeg($content);

But that did not work, meaning adding the other watermark code will not work either. Any suggestions as to how to modify the zip code to include the watermark would be greatly appreciated.

I basically do not understand the difference between what is created in $im with imagecreatefromjpeg and what is extracted to $output from the zip archive. I assume that $output contains the raw jpg file data, but have no idea what $im contains.

  • 写回答

1条回答 默认 最新

  • dongpan2788 2014-04-11 22:13
    关注

    UPDATE: Answered my own question. All I needed was to add the following after getting $content from the zip:

    $im = imagecreatefromstring($content);
    

    I can then apply the watermark exactly as in the first example. Hope that helps others.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题