Jump to content

Adding Custom Text To An Image

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
I have this code to put a text on an image

<?php

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

$string = "test";

// try changing this as well

$font = 4;

$width = imagefontwidth($font) * strlen($string) ;

$height = imagefontheight($font) ;

$im = imagecreatefrompng("test.png");

$x = imagesx($im) - $width ;

$y = imagesy($im) - $height;

$backgroundColor = imagecolorallocate ($im, 255, 255, 255);

$textColor = imagecolorallocate ($im, 0, 0,0);

imagestring ($im, $font, $x, $y, $string, $textColor);

imagepng($im);

?>

but it shows me these weird symbols all over the page
what could be the problem?

#2
devnick

devnick

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

The code looks perfect. Usually garbled values are shown if the content type is not right

#3
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
i double checked everything
the file path, the text, the codes...

but everytime i test it out
it shows me all this weird symbols all over the page

#4
t3tris

t3tris

    Newbie

  • Members
  • Pip
  • 5 posts
header("content-type: image/png")

#5
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
are you trying to say its case sensitive?

#6
t3tris

t3tris

    Newbie

  • Members
  • Pip
  • 5 posts
no, no. I messed up. I'm sorry, I didn't see that you had the header already. I just ran it though, and it shows the image on my server. I'm not sure...

#7
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
yeah i got it working already...
it has messed up with the headers.

i didnt see there was an include file that has another header content type