question again :)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

question again :)

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post 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 
     } 
}
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

hi,

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

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

should do.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post 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?
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

i'm still pondering this.. I've breen trying lots of different stuff nothing works..

plz help.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

wow i didn't relsie lolol it uses the commas between the numbers thanks volka!!!!! smart one! :D
Post Reply