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 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿