Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Image manipulation

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion

Image manipulation
Reply
 
Thread Tools
Old 29-05-2004, 18:28   #1
Tricky
Inactive
 
Tricky's Avatar
 
Join Date: Jun 2003
Location: I am house...
Services: $KY+HD - BT Infinity
Posts: 2,284
Tricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful one
Image manipulation

Found this link on the web: http://www.ryano.net/iraq/

It allows you to enter some text that when submitted becomes part of the image (if you right click and save - the text is within the image). Anyone know how they do it or can point me in the direction of site that shows me how. I would like to create a similar function for one of my websites.

Thanks in advance...
Tricky is offline   Reply With Quote
Advertisement
Old 29-05-2004, 19:50   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

I've already written something similiar. I was writing it so I can have a random generated sig on this board. It basically works, but I still want to tweak the text position/alignment but anyway, here is the important code:

Code:
<?php

//define what pic you want to alter and text
$thepic = 'img.jpg';
$thestring= "text\ntext";  //  \n for new line

//load the image (also you can use imagecreatefromgif)
$im = imagecreatefromjpeg($thepic);


//blue text
$textcolor = imagecolorallocate($im, 0, 0, 255);
 
//write text - the number params are: fontsize, angle to write, x position, y position
imagettftext($im, 12, 0, 0, 0, $textcolor,'arial.ttf',$thestring);

//output image to browser.
  header("Content-type: image/jpg");
  imagejpeg($im);

?>
Note: you can't output GIFs due to Compuserve copyright law. If you want to output transparency, use content-type: image/png, and imagepng. Also, the font has to be stored locally on the server. So just copy arial.ttf from c:\windows\fonts and upload it to your server.

To call it, include this in your HTML file:

Code:
<img src="imagemanipulated.php"></img>
If you want more info go to: http://uk.php.net/manual/en/function.imagettftext.php

HTH
punky is offline   Reply With Quote
Old 29-05-2004, 21:14   #3
Tricky
Inactive
 
Tricky's Avatar
 
Join Date: Jun 2003
Location: I am house...
Services: $KY+HD - BT Infinity
Posts: 2,284
Tricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful one
Re: Image manipulation

Thanks for your help it would appear that I-WEB don't support TTF ...
"Call to undefined function: imagettftext()"

O well back to the drawing board!!!
Tricky is offline   Reply With Quote
Old 29-05-2004, 21:27   #4
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

You need the GD and FreeType library. I'd ask them to add it, although they should have by default. Give KingPhoenix a nudge.

If he won't, I might have to start renting out my PHP server On the brightside it might be 400k upload soon
punky is offline   Reply With Quote
Old 29-05-2004, 22:04   #5
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: Image manipulation

I-web has the latest GD library, I use it regularly, not sure about Freetype though.
Bifta is offline   Reply With Quote
Old 29-05-2004, 22:15   #6
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

If it is running, it should say, under the GD section of phpinfo():

GD Support enabled
FreeType Support enabled
punky is offline   Reply With Quote
Old 30-05-2004, 14:10   #7
Tricky
Inactive
 
Tricky's Avatar
 
Join Date: Jun 2003
Location: I am house...
Services: $KY+HD - BT Infinity
Posts: 2,284
Tricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful oneTricky is the helpful one
Re: Image manipulation

Now running on both I-WEB servers - Top marks to KP.
Tricky is offline   Reply With Quote
Old 30-05-2004, 14:37   #8
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: Image manipulation

Punky, that script works well, though, I've managed to **** it up already, I've got a form which you slap the text in and it uses GET to send the URL string e.g. www.blah.com/content=whatevertextstring then the php file I've altered to use:

$thestring = $_GET["content"];

It just seem's to put odd characters up, must be something to do with it not reading it as a text field or something.

(also, is there any way of centering the text horizontally on the image?)
Bifta is offline   Reply With Quote
Old 30-05-2004, 15:56   #9
willie
Inactive
 
willie's Avatar
 
Join Date: Jun 2003
Location: Ra Port
Age: 73
Services: VM 200mb VM Phone M
Posts: 566
willie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these partswillie is just so famous around these parts
Send a message via MSN to willie
Re: Image manipulation

Quote:
Originally Posted by Tricky
Now running on both I-WEB servers - Top marks to KP.
They always where enabled on servers just need to check that they are latest version
willie is offline   Reply With Quote
Old 30-05-2004, 15:58   #10
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

I don't know what you are doing wrong as it works here. If you get funny symbols in there, like squares, you may be using symbols that aren't in the font set. Make sure, for the moment, you only use alphanumeric characters.

Without looking at the code, it is hard to see what you are doing, but here is what you should have, if you want to set the text via a form:

Code:
<?php

if (isset($_GET["content"]))
{
Then your image munipulation code as before, then:

Code:
}

else

{
?>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="text" name="content">
<input type="submit">

</form> <?php

}

?>
Run the file say file.php, and as there is nothing to get, it will show you the form. Once you click on it, it will reload itself, and as $_GET is set again, so it will display the image. I can't see whats wrong with your code, but doing that works for me. PM it over andi'll take a look if you still can't get it working.

For centring the text: This isn't the most concise way, but it is the way that makes it easiest to understand. Replace the imagettftext line with this:

Code:
//center text
//work out how big the text is
$bounds = imagettfbbox(12,0,'arial.ttf',$thestring);

//get width - right x coord - left x coord
$textwidth = $bounds[2] - $bounds[0];

//get offset
$textoffset = $textwidth / 2;

//calc start pos - half the image size minus offset - middle of image should be middle of text.
$textstartpos = (imagesx($im)/2) - $textoffset;
  
//write text - note 0 has become $textstartpos
imagettftext($im, 12, 0, $textstartpos, 20, $textcolor,'arial.ttf',$thestring);
HTH mate.

Just as a helpful reference, here is the whole of my code:

Code:
<?php

if (isset($_GET["content"]))
{

//define what pic you want to alter and text
$thepic = 'img.jpg';
$thestring= $_GET["content"];




//load the image (also you can use imagecreatefromgif)
$im = imagecreatefromjpeg($thepic);


//blue text
$textcolor = imagecolorallocate($im, 0, 0, 255);

  $bg = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $bg);

//center text
$bounds = imagettfbbox(12,0,'arial.ttf',$thestring);

//get width
$textwidth = $bounds[2] - $bounds[0];

//get offset
$textoffset = $textwidth / 2;

//calc start pos
$textstartpos = (imagesx($im)/2) - $textoffset;
 
 
//write text 
imagettftext($im, 12, 0, $textstartpos, 20, $textcolor,'arial.ttf',$thestring);

//output image to browser.
  header("Content-type: image/png");
  imagepng($im);

}

else

{
?>
<form action = "<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="text" name="content">
<input type="submit">

</form> <?php

}

?>
Edit: If you want to call it from a separate file, use this code instead to call the image munipulation:

File: callimagemunip.php
Code:
<html>
<body>
<img src="imagemunip.php<?php echo "?content=". $_GET["content"]; ?>"></img>

<form action="callimagemunip.php">
<input type="text" name="content">
<input type="submit">
</form>
</body>
</html>
punky is offline   Reply With Quote
Old 30-05-2004, 16:23   #11
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: Image manipulation

I'd use a slightly different version:

PHP Code:
<?php

if (!empty($_GET["content"]))
{

//define what pic you want to alter and text
$thepic = 'img.jpg';
$thestring= $_GET["content"];

//load the image (also you can use imagecreatefromgif)
$im = imagecreatefromjpeg($thepic);

//blue text
$textcolor = imagecolorallocate($im, 0, 0, 255);

  
$bg = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $bg);

//center text
$bounds = imagettfbbox(12,0,'arial.ttf',$thestring);

//get width
$textwidth = $bounds[2] - $bounds[0];

//get offset
$textoffset = $textwidth / 2;

//calc start pos
$textstartpos = (imagesx($im)/2) - $textoffset;
  
//write text 
imagettftext($im, 12, 0, $textstartpos, 20, $textcolor,'arial.ttf',$thestring);

//output image to browser.
  
header("Content-type: image/png");
  
imagepng($im);

}
else
{
echo 
"<form action=\"$_SERVER['PHP_SELF']\"><input type=\"text\" name=\"content\"><input type=\"submit\"></form>";
}
?>
The main changes being the !empty part and the bottom form HTML.
It says something like "if content is not empty then do this, otherwise echo the form out".
Richard M is offline   Reply With Quote
Old 30-05-2004, 16:25   #12
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: Image manipulation

Ah now that works ok, all I have to do now is stop it antialiasing so I can use 9 point verdana.

http://www.se-an.co.uk/test.php

I'm sure there's a setantialias command, but I can't find any reference to it from google.
Bifta is offline   Reply With Quote
Old 30-05-2004, 16:44   #13
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

You can turn it off using:

http://uk.php.net/manual/en/function.imageantialias.php

just use imageantialias($im,false);
punky is offline   Reply With Quote
Old 30-05-2004, 16:54   #14
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: Image manipulation

Quote:
Originally Posted by punky
You can turn it off using:

http://uk.php.net/manual/en/function.imageantialias.php

just use imageantialias($im,false);
Heh, I was was trying (no) and (0) and getting nowhere.

If you stick a "-" in from the the $textcolor it seems to take some of the antialiasing off.
Bifta is offline   Reply With Quote
Old 16-06-2004, 01:01   #15
justme
Inactive
 
Join Date: Jun 2004
Posts: 1
justme is an unknown quantity at this point
Re: Image manipulation

phpinfo indicates:

GD Support enabled
FreeType Support enabled


yet line 24 (using Punky's whole of code post)



$bounds = imagettfbbox(12,0,'arial.ttf',$thestring);



errors with


Warning: Could not find/open font in /home/my_account/public_html/pix/pix.php on line 24


and arial.ttf is in the same folder as pix.php



Any ideas why the error as I have tried it as
$bounds = imagettfbbox(12,0,'arial.ttf',$thestring);
and
$bounds = imagettfbbox(12,0,'/home/my_account/public_html/pix/arial.ttf',$thestring);

wuth the same error?!
justme is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:36.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum