Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Editing a PSD file via PHP, and saving it.
PostPosted: January 29th, 2010, 5:03 pm 
Rsbandb Donor
User avatar
Offline

Joined: February 4th, 2006, 5:40 pm
Posts: 1832
Location: 127.0.0.1
RS Status: P2P
I am looking to edit a PSD with a PHP script, like change a string of text, and then safe it as a PNG.

Kind of like how this site does their Runescape stat signatures.

Could anyone help? Thanks.

_________________
Image
Mike wrote:
Say NOOOOOOOOOOOOOOOOOOOO to star trek


Top
 Profile  
 
 Post subject: Register and login to get these in-post ads to disappear
PostPosted: January 29th, 2010, 5:03 pm 
Rsbandb Donor

Joined: September 9th, 2004, 1:47am
Posts: 9047
Location: In your web browserz


Top
  
 
 Post subject: Re: Editing a PSD file via PHP, and saving it.
PostPosted: January 29th, 2010, 5:34 pm 
Rsbandb Donor
Offline

Joined: October 25th, 2004, 10:12 pm
Posts: 3055
Location: New Zealand nz
RS Name: Chief. Snake
RS Status: Retired
Clan Name: Bits and Bytes
I don't think you'd want to go down that road as it would be near impossible. The reason you can't see any special styles or blending options on text in our stat sigs (or the stat sigs of any other site for that matter) is because all of the dynamically generated text is added by the PHP GD library itself.

In other words we don't use PSDs. :P

_________________


Top
 Profile  
 
 Post subject: Re: Editing a PSD file via PHP, and saving it.
PostPosted: January 29th, 2010, 5:41 pm 
Rsbandb Donor
User avatar
Offline

Joined: February 4th, 2006, 5:40 pm
Posts: 1832
Location: 127.0.0.1
RS Status: P2P
Oh.

Well basically, I just want a background, and be able to generate text where I want it to go.

Would that be easily possible?

And thanks for the explanation. I haven't worked with the GD library much before.

_________________
Image
Mike wrote:
Say NOOOOOOOOOOOOOOOOOOOO to star trek


Top
 Profile  
 
 Post subject: Re: Editing a PSD file via PHP, and saving it.
PostPosted: January 30th, 2010, 12:22 am 
Rsbandb Donor
Offline

Joined: October 25th, 2004, 10:12 pm
Posts: 3055
Location: New Zealand nz
RS Name: Chief. Snake
RS Status: Retired
Clan Name: Bits and Bytes
Oh yep, that's quite possible.
If you're interested in adding effects to the texts there's not a lot that the GD library can do except add makeshift shadows by duplicating the text and moving it appropriately as shown below. If you don't want the shadow then just get rid of that one line.

This code outputs an entire image (I adapted this from code that I used for a blog signature) so it'll do exactly what you want it to.

Code:
<?php
// The lines below prevent the file from being cached (i.e. it is reloaded upon each view) and are currently commented - should only be uncommented if you are outputting dynamic information which will be regularly updated, and also if you don't mind using a lot of bandwidth on your host. You can use MySQL or an RSS grabber etc to output stuff dynamically.
#header("Expires: Mon, 26 Jul 1997 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("Cache-Control: max-age=0");
#header("Pragma: no-cache");
header("Content-type: image/x-png"); // can use 'Content-type: image/jpeg/gif/x-png' instead (change output at end also)

// Load image template
$im = imagecreatefrompng("background.png"); // location of the background image (should also be imagecreatefromjpeg/gif if the file type is not png)
$textcolour = imagecolorallocate($im, 255, 255, 255); // colour of the text you're adding in an RGB value
$textshadow = imagecolorallocate($im, 0, 0, 0); // colour of the shadow on your text (if any) in an RGB value

// The following function gives text center alignment
function centerText($size, $angle, $font, $text, $centerPt){
   $bbox = imagettfbbox($size, $angle, $font, $text);
   $width = $bbox[2] - $bbox[0];
   $halfPt = $width / 2;
   $newX = $centerPt - $halfPt;
   return $newX;
}

// imagettftext ($im, font size, angle, location x-coord, location y-coord, font colour using imagecolorallocate() function, font file location, text);
// the centerText() function is a bit confusing to grasp but it goes in the x-coord parameter and you basically enter the same parameters into it as you did for the rest of the imagettftext() function. Read its parameters above to see what to enter.
// First apply a shadow (1px off the actual text), then actual text afterwards
$text = "This is the string of text you want to output";
imagettftext ($im, 20, 0, centerText(20, 0, './verdana.ttf', $text, 85) + 1, 87, $textshadow, "./verdana.ttf", $text);
imagettftext ($im, 20, 0, centerText(20, 0, './verdana.ttf', $text, 85), 86, $textcolour, "./verdana.ttf", $text);

// Throwing out the final image
imagepng($im);
// or
// imagepng($im);
// or
// imagejpeg($im,'',100);
// (change content-type in header also as necessary)

// Free the memory
imagedestroy($im);
?>

_________________


Top
 Profile  
 
 Post subject: Re: Editing a PSD file via PHP, and saving it.
PostPosted: January 30th, 2010, 2:44 am 
Rsbandb Donor
User avatar
Offline

Joined: February 4th, 2006, 5:40 pm
Posts: 1832
Location: 127.0.0.1
RS Status: P2P
Thank you very much, this code was helpful.

Problem resolved.

_________________
Image
Mike wrote:
Say NOOOOOOOOOOOOOOOOOOOO to star trek


Top
 Profile  
 
Display posts from previous:  Sort by  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to: