I am writing a program that watermarks user uploaded photos. After completing the layering, imagePNG() outputs the photo to the browser but wont save it to a directory. The paths are all correct and file permissions altered to 0755. Using only the first parameter of the function ( imagePNG($image) ) the image outputs, however when the path is added ( imagePNG($image, "photo_uploads/" . $album_name . "/") ).
Code:
<?php
session_start();
use PHPImageWorkshop\ImageWorkshop;
$album_length = $_SESSION['album_length'];
$extension_array = $_SESSION['extension_array'];
$album_name = $_SESSION['album_name'];
chmod("photo_uploads/" . $album_name . "/", 0777);
for($i = 0; $i < $album_length; $i++) {
$path = 'photo_uploads/' . $album_name . '/' . $i . $extension_array[$i];
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('watermark.png');
//only works with png
$im = imagecreatefrompng($path);
// 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');
$save = "photo_uploads/" . $album_name . "/";
imagePNG($im, $save);
imagedestroy($im);
}
?>
I have tried all of the solutions for other similar question. The function continues to output the modified image unless a path to save to is added as a second parameter.