SigGP
SigGP

Reputation: 786

PHP gd - watermark - how save image?

I have on server the image. I want to make a watermark (text) on image and save this image as a new with other name. My function is:

function watermark($path, $watermark){
    $imageURL = $path;
    list($width,$height) = getimagesize($imageURL);
    $imageProperties = imagecreatetruecolor($width, $height);
    $targetLayer = imagecreatefromjpeg($imageURL);
    imagecopyresampled($imageProperties, $targetLayer, 0, 0, 0, 0, $width,      $height, $width, $height);
    $WaterMarkText = $watermark;
    $watermarkColor = imagecolorallocate($imageProperties, 191,191,191);
    imagestring($imageProperties, 5, 130, 117, $WaterMarkText, $watermarkColor);
    imagejpeg ($imageProperties);
    imagedestroy($targetLayer);
    imagedestroy($imageProperties);
}

where parameters are:

$watermark = $_POST['watermark'];
$path = "/images/$file_name";

When I start the scypt, the image with watermark is creating and displays on screen. My aim is to not display the new image but save in the same folder with name: $file_name_watermark. How can i do this?

Upvotes: 0

Views: 212

Answers (1)

Mitya
Mitya

Reputation: 34598

From the docs on imagejpeg():

filename

The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.

So:

imagejpeg ($imageProperties, 'some/path.jpg');

Upvotes: 2

Related Questions