SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wiriting text onto a PNG and rendering

    I'm having some problems trying to figure this one out.

    I'd like to create .png's based on data I've pulled off a webpage.

    I currently have it setup to where it adds the text to the png, but it doesn't create and upload a new png, its my same base.png just with text positioned over it. I'd like to get it to render that out, or find a different method for the same thing. I'm using GD Library, but am not very familiar with it.

    Any ideas?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,430
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    You must be using the same input and output filename - post your code to get help with it.

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    You must be using the same input and output filename - post your code to get help with it.
    Code:
    Code PHP:
    <?php
    $image = ImageCreateFromPNG($_GET['base1']);
    $color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
    $colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
    $font = $_GET['font'];
    $fontSize = $_GET['fsize'];
    $fontRotation = $_GET['frot'];
    $str = $_GET['str'];
     
    /* Shadow */
    ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str);
     
    /* Top Level */
    ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str);
     
    header("Content-Type: image/PNG");
    ImagePng ($image);
    imagedestroy($image);
    ?>
    That is the code, basically C+P'd off another website, but its not exactly what I'm looking for. It creates the png by just overlapping text and variables on it, but I'd like for it to render out the actual image and upload it to my server. This would make custom .png's for every entry.

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,430
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    This is the area you need to look at and as you say it is displaying the image without saving it.
    PHP Code:
    header("Content-Type: image/PNG");
    ImagePng ($image);
    imagedestroy($image); 
    Change it to:
    PHP Code:
    ImagePng ($image"new_file_name");
    // OR
    // ImagePng ($image, $new_file_name);
    imagedestroy($image); 

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, I seem to have gotten that all worked out.

    Now I'm using GD Library, but need to transfer a variable and value from one file.php to anotherfile.php.

    I'm trying to use the $_SESSION like so;
    Code PHP:
    File.php:
    $_SESSION['gt'] = $gt
    ~~~~~~~
    AnotherFile.php:
    $gt = $_SESSION['gt']

    This seems to give an error to the line of code following the AnotherFile.php. And also an error to the line of code following the code listed above in File.php.

    Am I using $_SESSION in a wrong manner?

    Edit: /SlitWrists

    I forgot the semicolon (";").

  6. #6
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got that whole problem worked out ^^

    But now I'm running into a problem. I ended up including the 2 files in eachother's, that way I can just call the variables like normal.

    However, this gave me an error with the header. It seems to think

    Code:
    header("Content-Type: image/PNG");
    AND
    Code:
    <style type="text/css">
    Are the same. I closed the <style> brackets and everything. I'm not sure why its giving me the error.

    Cannot modify header information - headers already sent by (output started at directory/index.html:6) in directory/script.php on line 20

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For experiment remove the line
    header("Content-Type: image/PNG");
    Let PHP to decide the content type.

  8. #8
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    If you're going to send a header() call, it must be done before ANY output is sent to the browser.
    images should not be included. If you're using php to generate the image, just use the php file as the SRC of the image tag.

    <img src='picture.php'> is completely valid as long as picture.php returns data consistent with an image format (has the right header and such.)

  9. #9
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    If you're going to send a header() call, it must be done before ANY output is sent to the browser.
    images should not be included. If you're using php to generate the image, just use the php file as the SRC of the image tag.

    <img src='picture.php'> is completely valid as long as picture.php returns data consistent with an image format (has the right header and such.)
    That is exactly what I was doing, but in the file called 'picture.php' I wanted to access a variable in the original file. I was going to name my png file equal to a $variable.png.

  10. #10
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,430
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    From memory you can access a variable but can not remember how I did it now; I think something like this worked:

    PHP Code:
    <img src='picture.php?variable.png'>
    OR
    <
    img src='picture.php?variable=variable.png'
    Last edited by Rubble; Aug 8, 2011 at 13:09. Reason: modified code with variable.png

  11. #11
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Rubble View Post
    From memory you can access a variable but can not remember how I did it now; I think something like this worked:

    PHP Code:
    <img src='picture.php?variable.png'>
    OR
    <
    img src='picture.php?variable=variable.png'
    I'd like to try and keep the url as clean as possible.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •