php 在 s3 导入的图像上添加水印

标签 php amazon-s3 watermark php-gd

我正在尝试在图像上添加水印。

图片和水印图片都是从aws s3导入的。

我试过了

      $watermark = tempnam(sys_get_temp_dir(), 'watermark.png');

        //save the file from s3 storage to the temporary file
        $content=$this->s3Manager->getFile('watermark.png',$this->verb,$watermark);
    // Set the margins for the stamp and get the height/width of the stamp image
        $marge_right = 10;
        $marge_bottom = 10;

list($watermark_width,$watermark_height) = getimagesize($watermark);

//Get the width and height of your image - we will use this to calculate where the watermark goes
$size = getimagesize($tempFile);

//Calculate where the watermark is positioned
//In this example, it is positioned in the lower right corner, 15px away from the bottom & right edges
$dest_x = $size[0] - $watermark_width - 15;
$dest_y = $size[1] - $watermark_height - 15;


imagecopy($tempFile, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
//Finalize the image:


        imagejpeg($tempFile);


        return $tempFile;

imagecopy 方法失败 -

"imagecopy() expects parameter 1 to be resource, string given in.

我检查了图像是否由 dest_y 和 dest_x 成功导入,它们似乎没问题。

最佳答案

如错误所述,imagecopy 需要资源。我假设 tempfile 是一个字符串。你可以这样做

$res = imagecreatefrompng($tempfile)

并将其传递给 imagecopy

关于php 在 s3 导入的图像上添加水印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29674956/

相关文章:

amazon-web-services - 在 s3 中启用版本控制的成本

python - SignatureDoesNotMatch - Boto3 Django 存储

php - .htaccess url 重写现有目录

php - amazon-s3-php-class - 如何更改权限

image - 为图像嵌入不可见鲁棒水印的算法

python - 在 Python 中创建水印

objective-c - 如何 'watermark' PDF文件?

xml - 新的 SimpleXMLElement - xlink :href - namespace error

php - PDO PHP SQLite3 数据库连接一般错误14

php - CodeIgniter 数据库迁移错误