Results 1 to 3 of 3
Thread: php image generator script
-
07-13-2009, 03:29 AM #1Junior Guru Wannabe
- Join Date
- Mar 2004
- Posts
- 77
php image generator script
Hi -
I am looking for a php script that would create an image for me.
E.g., take background and a string text as value and create a jpg with that text.
If you nave one of heard of one, I'll appreciate your help/pointers.
Thanks
GMWeb Hosting and Cloud Hosting in Australia
-
07-13-2009, 10:01 AM #2Junior Guru Wannabe
- Join Date
- Mar 2009
- Posts
- 32
Here's some code I used in a previous project of mine that I've modified a tiny bit for ya. Might be overkill, but it'll do the job:
Code:<?php function imagecreatefromext($filename) { $ext = substr($filename, strrpos($filename, '.')+1); $ext = $ext == 'jpg' ? 'jpeg' : $ext; $f = 'imagecreatefrom'.$ext; return $f($filename); } function hex2rgb($hexstr, $rgb=NULL) { $int = hexdec($hexstr); switch($rgb) { case "r": return 0xFF & $int >> 0x10; break; case "g": return 0xFF & ($int >> 0x8); break; case "b": return 0xFF & $int; break; default: return array( "r" => 0xFF & $int >> 0x10, "g" => 0xFF & ($int >> 0x8), "b" => 0xFF & $int ); break; } } function hex2col($image, $hexstr, $rgb=NULL) { $hex = hex2rgb($hexstr); return imagecolorallocate($image, $hex['r'], $hex['g'], $hex['b']); } function set_size($size) { global $opt_size; $opt_size = is_numeric($size) ? $size : $opt_size; } function set_color($color) { global $opt_color, $im; $opt_color = hex2col($im, $color); } function add_text($string, $x, $y) { global $opt_color, $opt_size, $text; $text[] = array('t'=>$string, 'x'=>$x, 'y'=>$y, 'c'=>$opt_color, 's'=>$opt_size); } function create($banner) { global $im; $im = imagecreatefromext($banner); } function output() { global $im, $text; foreach($text as $key=>$opts) { imagettftext($im, $opts['s'], 0, $opts['x'], $opts['y'], $opts['c'], 'fonts/verdana.ttf', $opts['t']); } header('Content-type: image/png'); imagepng($im); } create('images/bg.png'); // Supply a background image set_size(12); set_color('#00FF00'); add_text('This is my string 1', 15, 15); // This will be size 12 #00FF00 at (15,15) set_size(10); add_text('This is my string 2', 30, 33); // This will be size 10 #00FF00 at (30,33) set_color('#0000FF'); add_text('This is my string 3', 45, 50); // This will be size 10 #0000FF at (45,50) output(); ?>
http://www.runecrypt.com/freelance/banners/index.php
-
07-21-2009, 01:57 PM #3Junior Guru Wannabe
- Join Date
- Jul 2009
- Posts
- 63
if you have shell access you should implement imagemagick w/php its super easy to use.
Similar Threads
-
$50 Fifteen SEO Script Mega Package with NEW Dynamic PageRank Image Generator!
By MSHadmin in forum Software & Scripts OffersReplies: 0Last Post: 10-03-2007, 10:31 AM -
Random number generator script
By markjut in forum Programming DiscussionReplies: 7Last Post: 04-23-2007, 01:05 AM -
Post Reader - Blog RSS Image Generator
By Jako in forum Domain Name with Web Site OffersReplies: 3Last Post: 04-04-2007, 04:42 PM -
batch image bb code generator
By roby2k in forum Programming DiscussionReplies: 2Last Post: 03-06-2006, 01:41 AM