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

  • Home
  • SEARCH
  • 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 3345354
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:10:34+00:00 2026-05-18T01:10:34+00:00

I’m working on a script to put watermarks on images uploaded by users. Because

  • 0

I’m working on a script to put watermarks on images uploaded by users. Because every user wants his own user name on his picture, I decided to make a transparent PNG first with the name of the user. After that I use a simple watermark technique to merge the PNG and uploaded files together.

I got the script working, but it keeps showing me my current address every time a PNG is created.

This is the code so far:

 <?php
    session_start();

    $username = $_SESSION['login'];
    $filename = "watermarks/$username.png";

    if (file_exists($filename)) {
        exit;
    } elseif ($filename == "undefined") {
        exit;
    }else{


    header("Content-type: image/png"); //Picture Format
    header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Pragma: no-cache"); // NO CACHE

    /*image generation code*/
    //create Image of size 350px x 75px
    $bg = imagecreatetruecolor(500, 100);

    //This will make it transparent
    imagesavealpha($bg, true);

    $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
    imagefill($bg, 0, 0, $trans_colour);

    //Text to be written
    $text = $username;

    // White text
    $white = imagecolorallocate($bg, 255, 255, 255);
    // Grey Text
    $grey = imagecolorallocate($bg, 128, 128, 128);
    // Black Text
    $black = imagecolorallocate($bg, 0,0,0);

    $font = 'fonts/LiberationSans.ttf'; //path to font you want to use
    $fontsize = 20; //size of font


    //Writes text to the image using fonts using FreeType 2
    imagettftext($bg, $fontsize, 0, 125, 50, $black, $font, $text);

    imagettftext($bg, $fontsize, 0, 127, 52, $white, $font, $text);




    //Create image
    header( "Content-type: image/png" );
    //imagepng($bg);

    $save = $filename;
    imagepng($bg, $save, 0, NULL);


    //destroy image
    imagedestroy($bg);

    }
    ?>

I’m sure I missed something, but I can’t figure out what.

My second problem is that I can not figure out how to get the text to the center and get rid of the white space around the text.
alt text

Please download the image to see what I mean.

Thanks in advance for your help.

  • 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-18T01:10:34+00:00Added an answer on May 18, 2026 at 1:10 am

    You’re not outputting the image. Most browsers will just display the current url when the headers indicate an image, but no data is sent.

    Notice how you’re providing a filename to imagepng()? If you read the PHP manual on imagepng() it says it will either output the image if no filename to save to is present, OR save the image to the filename specified.

    You need to either remove all the arguments after $bg to output the image, or after imagedestroy($bg); you need to open the output file at $save and re-output it.

    Something like the following will stream a file to the output:

    <?php
    $fp = fopen($save, 'r');
    while(!feof($fp)) {
        print fread($fp, 1024);
        ob_flush();
        flush();
    }
    fclose($fp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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.