Jump to content

Recommended Posts

Hello everybody,

 

I've been trying to solve this for a day now, maybe somebody has an idea!

 

Here's what I'm trying to do:

 

This is on a page that displays a photo from a database, along with some info that is displayed in a table below the photo. Things like photographer's name, date, and so on. The photo itself is a .jpg file that the photo display page pulls up according to the ?id= in the URL. However it only LOOKS like it's a jpg file, while in reality it loads a photo.php?id= but I've used a RewriteRule in .htaccess to make a request like, for example, "/photos/1.jpg" actually load "/photos/photo.php?id=1".

 

So far so good, this all works without any problems.

 

Now the reason I'm not simply displaying the jpg but going through the PHP file instead, is because I'm watermarking the image on the fly. So far, everything still works.

 

Now comes the problem.

 

The watermark is not the same on each photo. The watermark contains the photographer's name, so for each photographer I have a separate PNG watermark stored in a subfolder. Now I need to find out which one to load. The simple way would be to send the info through the file name, as you may remember I'm on a photo display page that has all the info after pulling it from the database, so I have the username readily available and I could pull up the image using "/photos/1.jpg?username=SOMEBODY", then have the RewriteRule translate this so I can use  $_GET['username'] in my photo.php, and everything's fine. However I want to keep this info out of the file name, because otherwise the user could change it manually and load somebody else's watermark on the photo. The user could simply change it to "/photos/1.jpg?username=SOMEBODYELSE"

 

So... here's what I want to do. Within my photo.php, I want to run a quick little mysql_query that checks within my database who is the photographer of this image. Sounds simple. But it seems that I can do all kinds of things on a page that contains a header("Content-type: image/jpg"); in the end, but NOT run a query. As long as I "//" the query part and manually specify the username through a variable, everything's ok. But as soon as there's a query in there, I get a red X.

 

Here's my code, maybe somebody has an idea. And thanks for reading this far, I understand it's kind of a tricky situation!

 

$photoid= $_GET['id'];

 

// now find the photographer's user id:

$query="SELECT * FROM photos WHERE photoid='$photoid'";

$result=mysql_query($query);

$photographer=mysql_result($result,$i,"photographer");

 

// now here comes the part where I join the photo and the watermark

$imagesource = $photoid.'.jpg';

$image = imagecreatefromjpeg($imagesource);

$watermark = imagecreatefrompng('watermarks/'.$photographer.'.png');

 

$imagewidth = imagesx($image);

$imageheight = imagesy($image);

$watermarkwidth = imagesx($watermark);

$watermarkheight = imagesy($watermark);

 

$startwidth = ($imagewidth - 400);

$startheight = ($imageheight - 20);

 

imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);

header("Cache-Control: max-age=3600");

header("Content-type: image/jpg");

imagejpeg($image,NULL,100);

imagedestroy($image);

imagedestroy($watermark);

 

Thanks for any help!

Yellowstone

Link to comment
https://forums.phpfreaks.com/topic/96554-mysql_query-possible-within-image/
Share on other sites

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.