Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to write dynamic text on a button in PHP

1 Answer

0 votes
// select the font
$font = "c:/Windows/Fonts/arial.ttf";
$size = 12;
// load the image
$image = imagecreatefrompng("c:/xampp/htdocs/webshopy.com/button.png");
// get the text width
$text_size = imagettfbbox($size, 0, $font, "hello");
// get the image center
$px = abs($text_size[2] - $text_size[0]);
$py = abs($text_size[5] - $text_size[3]);
$x = (imagesx($image) - $px) / 2;
$y = (imagesy($image) - $py) / 2 + $py;
// set text color
$color_black = imagecolorallocate($image, 0, 0, 0);
// draw text
imagettftext($image, $size, 0, $x, $y, $color_black, $font, "hello");
// output the image
header("Content-type: image/png");
imagepng($image);


answered Apr 15, 2014 by avibootz
edited Apr 15, 2014 by avibootz

Related questions

...