Page 1 of 1

Junk data

Posted: Wed Dec 20, 2006 9:30 am
by kpraman

Code: Select all

.....
$imagesource=$picNames; 
$filetype = substr($imagesource,strlen($imagesource)-4,4); 
$filetype = strtolower($filetype); 
if($filetype == ".gif")  $image = @imagecreatefromgif($imagesource);  
if($filetype == ".jpg")  $image = @imagecreatefromjpeg($imagesource);  
if($filetype == ".png")  $image = @imagecreatefrompng($imagesource);  
if (!$image) die(); 
$watermark = @imagecreatefrompng('watermark.png'); 
$imagewidth = imagesx($image); 
$imageheight = imagesy($image);  
$watermarkwidth =  imagesx($watermark); 
$watermarkheight =  imagesy($watermark); 
$startwidth = (($imagewidth - $watermarkwidth)/2); 
$startheight = (($imageheight - $watermarkheight)/2); 
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); 
imagejpeg($image, "images/$imagesource"); 
//imagejpeg($image); 
//imagedestroy($image); 
//imagedestroy($watermark);


$contents="
<form action='' method='post'>
  <table width='75%' border='0' align='center'>
    <tr>
    <td align='center'><div align='center'><input name='picture' type='image' src='images/$imagesource'></div></td>
  </tr>
</table>
</form>";
}

Code: Select all

"images/$imagesource"
. images is a folder and $imagesource is image name.

The above code works fine.

I do not want to create seperate watermarked file. So, i changed,

Code: Select all

imagejpeg($image, "images/$imagesource");
to

Code: Select all

imagejpeg($image);
and

Code: Select all

<td align='center'><div align='center'><input name='picture' type='image' src='images/$imagesource'></div></td>
to

Code: Select all

<td align='center'><div align='center'><input name='picture' type='image' src='$image'></div></td>
i am getting junk data, instead of image.

Posted: Wed Dec 20, 2006 9:39 am
by kaszu
It is not creating separate watermark file, but adding a watermark to a picture and then it saves to folder "images".
You are getting junk because if you remove second parameter from imagejpeg(resource image, [filename]) ,then image is outputed to browser not saved in file.

If i understand correctly you don't want image to be watermarked, then all what you need is:

Code: Select all

$imagesource=$picNames; 
$contents=" 
<form action='' method='post'>
  <table width='75%' border='0' align='center'>
    <tr>
    <td align='center'><div align='center'><input name='picture' type='image' src='$imagesource'></div></td>
  </tr>
</table>
</form>";

Posted: Wed Dec 20, 2006 10:42 am
by kpraman
I want the image to be watermarked. But, I do not want the watermarked images to be stored.

Posted: Wed Dec 20, 2006 10:54 am
by John Cartwright
you need to create another script, and have that script call the image script. It is not allowed to mix these two streams into one request.

... type='image' src='image.php?id=4'> ...

Then image script should then use readfile() to output the image as desired.