首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >强制下载前如何在图片上添加水印

强制下载前如何在图片上添加水印
EN

Stack Overflow用户
提问于 2012-12-13 19:48:13
回答 1查看 737关注 0票数 1

我想在的帮助下添加强制下载功能

代码语言:javascript
运行
复制
$this->load->helper('download');
$photo_path = "uploads/default/photos/".$photo;
$name = $photo_name.'.jpg';
$data = file_get_contents($photo_path); // Read the file's contents
$name = $photo_name.'.jpg';
force_download($name, $data); 

现在我想在下载image.is之前在图像上添加水印图像,这可以使用图像操作库,或者我应该尝试在上传文件时添加水印。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-13 20:06:10

下面是如何在将水印发送到force_download之前添加水印的方法:

代码语言:javascript
运行
复制
// Get the watermark from a file
$watermark = imagecreatefrompng('watermark.png');
$wmsize = getimagesize('watermark.png');
// Get your source image
$image = imagecreatefromjpeg($photo_path);
$size = getimagesize($photo_path);
// Set the watermark to be centered within the size of the destination image
$dest_x = ($size[0] - $wmsize[0]) / 2;
$dest_y = ($size[1] - $wmsize[1]) / 2;
// Copy the watermark over the original image
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $wmsize[0], $wmsize[1]);
// Use output buffering to capture the output to send to force_download
ob_start(); //Stdout --> buffer
imagejpeg($image); 
$img2 = ob_get_contents(); //store stdout in $img2
ob_end_clean(); //clear buffer
imagedestroy($image);
force_download($name, $img2);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13859188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档