Results 1 to 3 of 3
  1. #1

    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
    GM
    Web Hosting and Cloud Hosting in Australia

  2. #2
    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();
    ?>
    The output from that looks like this:
    http://www.runecrypt.com/freelance/banners/index.php

  3. #3
    if you have shell access you should implement imagemagick w/php its super easy to use.

Similar Threads

  1. Replies: 0
    Last Post: 10-03-2007, 10:31 AM
  2. Random number generator script
    By markjut in forum Programming Discussion
    Replies: 7
    Last Post: 04-23-2007, 01:05 AM
  3. Post Reader - Blog RSS Image Generator
    By Jako in forum Domain Name with Web Site Offers
    Replies: 3
    Last Post: 04-04-2007, 04:42 PM
  4. batch image bb code generator
    By roby2k in forum Programming Discussion
    Replies: 2
    Last Post: 03-06-2006, 01:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •