PHP中的图像水印 [英] Image watermarking in php

查看:68
本文介绍了PHP中的图像水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给图像加水印并保存.这是我正在使用的代码.在这里,它正在输出图像并将该输出存储到文件中.我想保存而不输出.

I want to watermark an image and save it. here is the code i am using for it. Here it is outputting the image and is storing that output to the file. I want to save it without outputting it.

// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('stamp.png');
$im = imagecreatefromjpeg('proverbs.jpeg');

// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
  imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy -   $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

// Output and free memory
header('Content-type: image/png');
ob_start();
// output jpeg (or any other chosen) format & quality
imagejpeg($im, NULL, 85);
// capture output to string
$contents = ob_get_contents();
// end capture
ob_end_clean();
//imagepng($im);
imagedestroy($im);
$fh = fopen("proverbs.jpeg", "w" );
fwrite( $fh, $contents );
fclose( $fh );

推荐答案

将其保存到文件中吗?

只需更改

imagejpeg($im, NULL, 85);

imagejpeg($im, 'image.jpg', 85);

这篇关于PHP中的图像水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆