我想在的帮助下添加强制下载功能
$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之前在图像上添加水印图像,这可以使用图像操作库,或者我应该尝试在上传文件时添加水印。
发布于 2012-12-13 20:06:10
下面是如何在将水印发送到force_download之前添加水印的方法:
// 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);
https://stackoverflow.com/questions/13859188
复制相似问题