0

I've got this script, which only saves the image at $image, and not the image at $newimage_2. Help?

<?php


$newimage_1 = imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $opacity);
$newimage_2 = imagecreatefromjpeg($newimage_1);

// print image to screen
header("content-type: image/jpeg");   
imagejpeg($image);
imagejpeg($newimage_2);
imagedestroy($image);  
imagedestroy($watermark);
imagedestroy($newimage_2);

?>
6
  • 2
    Not a solution to your problem, but imagecopymerge returns a bool and imagecreatefromjpeg takes a string. Commented Jan 26, 2011 at 15:19
  • @alexn - that's why i have imagejpeg afterwards Commented Jan 26, 2011 at 15:20
  • As alexn wrote imagecreatefromjpeg takes string (a "Path to the JPEG image") and it seems that your $newimage_1 is bool. Commented Jan 26, 2011 at 15:28
  • 1
    also, two imagejpeg() calls in one requests isn't going to work ... Commented Jan 26, 2011 at 15:32
  • @WideBlade: That's not relevant. alexn is right. Commented Jan 26, 2011 at 16:04

1 Answer 1

1
$source_file_path=$_FILES["image"]["tmp_name"];
$src = imagecreatefromjpeg($source_file_path);
list($width,$height)=getimagesize($source_file_path);
$newwidth=540;
$newheight=round(($height/$width)*$newwidth);
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$target_file_path = "images/".$filewhereyouwanttosaveit;

$watermark = imagecreatefrompng('imgs/copyright.png');
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = ($newwidth - $watermarkwidth);
$startheight = ($newheight - $watermarkheight);
imagecopy($tmp,$watermark,$startwidth,$startheight,0,0,$watermarkwidth,$watermarkheight);
imagegif($tmp,$target_file_path);

you probably dont need the resizing but code may help you...

imagegif or jpg or png or some else

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Man-exactly what i wanted!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.