Link to home
Start Free TrialLog in
Avatar of canuckconsulting
canuckconsultingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Need to create button similar to existing format

On an existing website I have several buttons which are as follows:

User generated image
User generated image
How can I create new buttons with different text using this same look?
Avatar of billfusion
billfusion

If these buttons specity inline style, then use that style.  Otherwise, and more likely, they use a style from either a CSS file or on the page itself.  In that case you can use that same style reference on you new buttons.

Here is an example with inline style:
<input type="button" name="btn_Test" value="Test" style="background-color:#66CCFF; color:white; border:2px solid silver; padding-left:20px; padding-right:20px" />

Open in new window

Avatar of canuckconsulting

ASKER

Sorry, I should have been clearer.  These buttons are images.  They are actually PNG files which I have inherited. I'm unfamiliar with how to manipulate the source images and change the text and size of the buttons.  Also matching the font is going to be a pain.

I had hoped this was a common problem others had faced.
Avatar of Robert Schutt
Taking the code from this site: http://fiddyp.co.uk/write-text-to-a-png-with-php/ and the background from one of your images I have made a page where you can create your own new button images:
http://schutt.nl/ee/Q_27827001/button.php?text=abcdef

I'm working on the font...
Is the text on the buttons part of the image?  Can you post a sample on a website I can take a look at?
Yes, the php code draws the text in the image and shows it, you can save the image to use on your website.

Here is a second version using the Verdana 8 font which seems close to what is used originally: http://schutt.nl/ee/Q_27827001/button2.php?text=Login 

If you have access to a php server you can use this modified code (also copy the verdana.ttf file):
<?php // code from: http://fiddyp.co.uk/write-text-to-a-png-with-php/
$im = imagecreatefrompng("btn-bg.png");
if(!$im) {
	die("");
}
$white = imagecolorallocate($im, 255, 255, 255);
$width = imagesx($im);
$height = imagesy($im);
$font = './verdana.ttf';
$fontsize = 8;
$text = $_GET['text'];
$angle = 0;
$bbox = imagettfbbox($fontsize, $angle, $font, $text);
$x = $bbox[0] + ($width - $bbox[4]) / 2;
$y = $bbox[1] + ($height - $bbox[5]) / 2 - 5;
imagettftext($im, $fontsize, $angle, $x, $y, $white, $font, $text);
Header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

Open in new window

Here is a page with some different versions: http://schutt.nl/ee/Q_27827001/compare.htm
Also made a compare2.htm with submit button added, must admit that the css styled button like @billfusion suggested look the best (and are buttons ;-), even when zooming in.

There's a problem with the generated images in that the baseline is not constant, I tried different calculations I found in the PHP manual but they each seem to have their shortcomings. Thinking now if you really want the images it would be easier to do in MS Paint (unless you need like a 100). Normally of course I would say Photoshop but you're not asking for wild shiny effects and such.
Looks like you did a good job in those examples.  

Another problem with the image generated buttons is that are fixed in size and do not adjust to the text.  For example http://schutt.nl/ee/Q_27827001/button2.php?text=testing Button.  Also it is adding unnecessary load on the server that has to process these images when they may not need to be dynamic.

If you do decide to use css, I would suggest removing the style from the element and use css classes to specify the syle.  That will give you more consistancy across the site.
ASKER CERTIFIED SOLUTION
Avatar of billfusion
billfusion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did say "you can save the image to use on your website" so I didn't mean for this to be used dynamically although with the right caching mechanisms in place it's not a problem.

I like the idea of the variable width, but maybe the site design calls for fixed width buttons?

Well, it's all academic if we don't hear back from the OP.

EDIT: that last line doesn't 'sound' right, I just meant we need your input, you have a lot of questions open at the moment.
@robert_schutt, right on on all points in your last post.
Hi guys and thank you so much for your efforts!

There is no requirement for fixed widths and in fact i prefer buttons sized appropriately.

@robert_schutt, how did you determine the correct colour and font to use for the CSS?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the help!  I have a much better understanding of my options. In the end I followed the CSS.