Jump to content

Recommended Posts

Hi

Im attempting to out put images with a water mark on the fly. I have a script that works fine. below.
The problem im experiancing has somthing to do with the header. Im unable to have any thing on the page other than the image with its water mark?


[quote]<?php 

header('content-type: image/jpeg'); 

$watermark = imagecreatefrompng('watermark.png'); 
$watermark_width = imagesx($watermark); 
$watermark_height = imagesy($watermark); 
$image = imagecreatetruecolor($watermark_width, $watermark_height); 
$image = imagecreatefromjpeg('image.jpg'); 
$size = getimagesize('image.jpg'); 
$dest_x = $size[0] - $watermark_width - 5; 
$dest_y = $size[1] - $watermark_height - 5; 
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 
imagejpeg($image); 
imagedestroy($image); 
imagedestroy($watermark); 

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><? print($header) ?></title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />

<meta name="description" content="" />
<meta name="keywords" content="" />

<script type="text/JavaScript" src="javascript.js"></script>

</head>

<body>

<p>text ... text ..text ... text ..text ... text ..</p>


</body>
</html>[/quote]
Link to comment
https://forums.phpfreaks.com/topic/35204-generating-water-marks-on-the-fly/
Share on other sites

Didnt think about that. However the following out puts the image but no text below

[quote]<?php 
header('content-type: image/jpeg'); 
$watermark = imagecreatefrompng('watermark.png'); 
$watermark_width = imagesx($watermark); 
$watermark_height = imagesy($watermark); 
$image = imagecreatetruecolor($watermark_width, $watermark_height); 
$image = imagecreatefromjpeg('image.jpg'); 
$size = getimagesize('image.jpg'); 
$dest_x = $size[0] - $watermark_width - 5; 
$dest_y = $size[1] - $watermark_height - 5; 
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 
imagejpeg($image); 
imagedestroy($image); 
imagedestroy($watermark); 

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>

<p>text ... text ..text ... text ..text ... text ..</p>

<? print($header) ?>

</body>
</html>[/quote]

I think the problem here is your not following the flow of your document.

Your program flow is doing exactly what your telling it by placing the the text and then the image.

What I think you want to try and do is utilise CSS and set a class on your <P> tag, or in fact the whole body tag to set your image as the background image.

If your aiming to have the watermark appear over your text you will need to use floats in CSS.
Ah I see,

Well from what I can glean from your script you are calling an image with the header function, watermarking it, destroying the image, destroying the watermark and then calling back header.

Try this,

[code=php:0]
<?php
header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg('image.jpg');
$size = getimagesize('image.jpg');
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($watermark);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>

<p>text ... text ..text ... text ..text ... text ..</p>

<? echo "<img src='{$image}' alt='' />"; ?>

</body>
</html>
[/code]
as far as i know, the original and suggested methods are not going to work due to the different headers required to send both an image and a picture. you cant send two content headers from the same script (the other being the default - text/html)
move all your PHP from before your DOCTYPE into a new file, called (for example) image.php. then where you want the image, you need:

[code]
<img src="/image.php" alt="" />
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.