3

I'm trying to add a watermark on an image.

Both , the image and the watermark image are imported from the aws s3.

I tried to do this

      $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;

It's failing on the imagecopy method -

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

I checked if the images a successfully imported by the dest_y and dest_x and they seems ok.

miken32
  • 42,008
  • 16
  • 111
  • 154
Aviv Paz
  • 1,051
  • 3
  • 13
  • 28

1 Answers1

1

As the error says, imagecopy wants a resource. I assume tempfile is a string. You can do this

$res = imagecreatefrompng($tempfile)

and pass this to imagecopy

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41