Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3315530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:21:40+00:00 2026-05-17T22:21:40+00:00

I’m having an issue using a watermarking script I have. Below is the script:

  • 0

I’m having an issue using a watermarking script I have. Below is the script:

if (isset($_GET['imgid'])) {
    include "../mysql_connect.php";
    $imgid = $_GET['imgid'];
    $query = "SELECT * FROM img_ref WHERE id='$imgid'";
    $result = mysql_query($query) or die(mysql_error());
    $row = mysql_fetch_array($result);
    $imagesource = "../ajax_uploads/$row[submitter_id]-uploads/$row[filename]";
} else {        
    $imagesource =  "../ajax_uploads/" . $_GET['path'];
}
$info = pathinfo($imagesource); 
$filetype = $info['extension']; 
if($filetype == "gif")  $image = @imagecreatefromgif($imagesource);  
if($filetype == "jpg")  $image = @imagecreatefromjpeg($imagesource);  
if($filetype == "png")  $image = @imagecreatefrompng($imagesource);  
if (!$image) die(); 
$watermark = @imagecreatefrompng('../images/watermark.png');
// This is the key. Without ImageAlphaBlending on, the PNG won't render correctly.
imagealphablending($image, true);
$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);
imagedestroy($image); 
imagedestroy($watermark); 

Now, if I pass a ‘path’ variable through, everything works fine and the image is displayed correctly as I would imagine. However, when I attempt to pass through an imgid value, and retrieve the path from the database, the image is presented in raw data on the screen – not as an image.

I have tried specifying the headers

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

However that hasn’t helped. It doesn’t seem to be an issue with the folder permissions, as if I specify the path name using the reference in the database, it works fine. It seems to be that including that first “if” section seems to break the output, and I’m at a loss why.

Could anyone possibly shed any light on this for me?

Thank you kindly,

Dan

UPDATE

Okay, somehow its started working with having “Header(“Content-type: image/jpeg”);” placed at the top of the PHP file, so if I go to the file directly and put in the GET id, I get the picture returned – which is good (no idea what changed though).

However I still have an issue in displaying this picture elsewhere it seems. I’m calling the picture using “fancybox”, a jquery plugin. When it displays the image, it is still showing the raw data. If I use the path, it displays fine – just for some reason the raw data shows up when using the GET id option. Am still looking into it but thanks for suggestions so far.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:21:41+00:00Added an answer on May 17, 2026 at 10:21 pm

    It seems using the header

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

    Seemed to work to get it to display as an image – however it did not work with fancybox for some reason. I looked at the API and have sinced forced fancybox to realise it is an image:

    $.fancybox({
                'href':'processes/process_watermark.php?imgid=' + id,
                'type':'image'
            });
    

    That makes it display correctly.

    Thanks for everyones help – and all the comments reminding me about SQL attacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.