Page 1 of 1

question again :)

Posted: Wed Oct 29, 2003 10:53 am
by nick2
Yep its me again lol

ok.. If I wanted to put text on an image.. say an exsisting image..

Code: Select all

<?php 
  header("Content-type: image/jpeg"); 
  $im = imagecreate(400,30); 
  $white = imagecolorallocate($im, 255,255,255); 
  $black = imagecolorallocate($im, 0,0,0); 
  
  // Replace path by your own font path 
  imagettftext($im, 20, 0, 10, 20, $black, "/path/arial.ttf", 
  "Testing... Omega: &#937;"); 
  imagejpeg($im); 
  imagedestroy($im); 
?>
Do I have to upload fonts or something? I don't understand that..

and if i'm correct this code creates an image with text on it.. it doesn't put text on an exsisting image..

anyway I am not asking for code I am just asking for some help:

how do I get these fonts?

I didn't understand the manual.

Posted: Wed Oct 29, 2003 11:39 am
by volka
the parameter fontfile has to point to an existing file on the server containing the truetype font.
It's almost the same as if you try to open a file via fopen (string filename, ...)
$im = imagecreate(400,30);
this creates an image resource, i.e. some kind of image that gd can handle; $im is used to tell gd which image is to be manipulated. Most of the gd functions do not affect files directly but the resource-image you pass as argument to the function. But there are functions to write(-back) resource-images to files, e.g.
int imagepng ( resource image [, string filename]), providing the second argument it tries to write the image to the file, otherwise it appends the image data to the output stream.

You can load an image from a file (e.g. with imagecreatefrompng()), manipulate it, and then write it back to the file (or not but sending it to the client, or even both if you like)

Posted: Wed Oct 29, 2003 12:17 pm
by nick2
Thanks any idea after the text is placed on the jpg image to change it to .jpg instead of .bmp as the output..

also...

any idea why this won't filter the file types?

Code: Select all

$dir = $_COOKIE[user];
$dh = opendir($dir); // open it for reading 
echo '<center></center><select name="imagef">'; // html 
while (($file = readdir($dh)) !== false) { // loop files 
if (($file != ".") and ($file != "..") and ($file != "_vti_cnf") and ($file !=".png") and ($file !=".bmp") and ($file !=".gif") and ($file !=".TIFF")) {
        echo "\n".' <option>' . $file .'</option>'; // each image html 
     } 
}

Posted: Wed Oct 29, 2003 12:34 pm
by gite_ashish
hi,

u r comparing ".png", ".gif" directly with $file, instead something like:

if (strstr($file) != ".png")

should do.

Posted: Wed Oct 29, 2003 12:47 pm
by nick2
Thanks a bunch , also could someone use their smart braina nd come up with an idea why this doesn't work?

I'm tyring to put a value from, $_POST[color] into a variable and it obviously won't work..

Code: Select all

<?
###Put text on the image### good luck nick #
Header("Content-type: image/jpeg");
Header("Expires: Mon, 1, 1999 05:00:00 GMT");
Header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
Header("Cache-Control: no-store, no-cache, must-revalidate");
Header("Cache-Control: post-check=0, pre-check=0", false);
Header("Pragma: no-cache");


##now we define the path to the image..and color settings? huh.###
//***************
// sig.jpg is a real image... This is what we write over

$im = imagecreatefromjpeg($_COOKIE[user] . "/" . $_POST[imagef]);
$mycolor = imagecolorclosest($im, $_POST[color]);

##what to write ##
imagestring($im, 3, $_POST[x], $_POST[y], $_POST[text], $mycolor);


##now we end it?##
Imagejpeg($im,'',90);
ImageDestroy($im); 
?>
now see where it says $mycolor = imagecolorclosest($im, $_POST[color]);

if i replace the $_POST[color] with a RGB number it will work.. ex. 250,0,0

any ideas?

edit: If I do and ($file !="wutvea") again 1 after another will it work?

Posted: Wed Oct 29, 2003 5:29 pm
by nick2
i'm still pondering this.. I've breen trying lots of different stuff nothing works..

plz help.

Posted: Wed Oct 29, 2003 5:47 pm
by volka
$mycolor = imagecolorclosest($im, $_POST[color]);
imagecolorclosest() takes four arguments, not two.
Now, before you reply "but the value of $_POST[color] is '255,0,0'", that's still one argument - a string ;)
you'd better either split this string or use three $_POST elements, like $_POST['red'], $_POST['green'], $_POST['blue']

btw: please have a read of http://www.php.net/language.types.array ... rray.donts

Posted: Wed Oct 29, 2003 6:16 pm
by nick2
wow i didn't relsie lolol it uses the commas between the numbers thanks volka!!!!! smart one! :D