/    Sign up×
Community /Pin to ProfileBookmark

GD Library – Transparency & Resize??? HELP!

I am working on a button generator for web designers.

I have a generator that puts text on a glossy button quite nicely. There are two more things I would like it to do:
1.) Support transparency (I have a script that does this, but cannot get it to work with the text)
2.) Resize the image and text (I also have a resize script, but again cannot get it to work with the text overlay).

Any ideas? Suggestions?

Here is the working script in action on the unfinished page:
[url]http://www.createbutton.com/glossy-buttons/[/url]

Here is the PHP code for the ‘engraved’ button:

[code=php]
<?php

// Set the content-type
header(‘Content-type: image/png’);

//Select background image
$buttonbg = $_POST[‘logo’];

$indent = $_POST[‘indent’];
$shadowindent = $indent + 1;
$reflectindent = $indent – 1;

// Create the image
$im = imagecreatefrompng(“$buttonbg”);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);

// The text to draw
$text = $_POST[‘label’];
// Replace path by your own font path
$font = ‘fonts/arial.ttf’;

// Add some shadow to the text
imagettftext($im, 24, 0, $shadowindent, 44, $white, $font, $text);

// Add some shine to the text
imagettftext($im, 24, 0, $reflectindent, 42, $black, $font, $text);

// Add the text
imagettftext($im, 24, 0, $indent, 43, $red, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);

?>
[/code]

The other codes are almost the same.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@janusmccarthyDec 14.2011 — I think you need to resample the image, not resize.

Look at an example for imagecopyresampled.
Copy linkTweet thisAlerts:
@donatelloauthorDec 15.2011 — Thanks for the suggestion... I have been trying that, to no avail...

I have a script that already resizes but does not preserve transparency, perhaps that is a better place to start? I did not want to use it because it writes to a file and then I must run a cron job to clean up the mess users leave behind.

Anybody else have any ideas?
Copy linkTweet thisAlerts:
@janusmccarthyDec 15.2011 — From your sample, it doesn't look like you're handling the alpha.

[code=php]
$newImg = imagecreatetruecolor($nWidth, $nHeight);
imagealphablending($newImg, false);
imagesavealpha($newImg,true);
$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
imagecopyresampled($newImg, $im, 0, 0, 0, 0,
$nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);
[/code]


http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/

Google: GD resize transparent
×

Success!

Help @donatello spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...