GFXVoid Graphic Design Forum

Remove Text Formatting
Loading...

» Online Users: 674

0 members and 674 guests
No Members online

» Site Navigation

 > FAQ

» Stats

Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
Welcome to our newest member, Lekelindids
Results 1 to 8 of 8

Thread: Image Generator

  1. #1
    Join Date
    Jan 2006
    Posts
    15

    Default

    Generates a random image from your list. Simply add more array values with your image url.

    GD Functions must be enabled in the PHP setup.

    Code:
    <?php
    
    // Images array
    $imgs = array();
    // add $imgs[__current#__] = "__IMGAGE_URL__"; for more images
    // image URLs must be relitive to the script
    $imgs[0] = "sig_one.jpg";
    $imgs[1] = "another_sig.jpg";
    $imgs[3] = "new_sig.gif";
    $imgs[4] = "yet_another_sig.png";
    
    // choose a random image
    $num = rand(0, sizeof($imgs) - 1);
    // do a check
    if(is_file($imgs[$num])){
    	// get type
    	if(strstr($imgs[$num], ".gif")){
     *// display gif image
     *header("Content-type: image/gif");
     *$im = imagecreatefromgif($imgs[$num]);
     *imagegif($im);
    	}elseif(strstr($imgs[$num], ".jpg") || strstr($imgs[$num], ".jpeg")){
     *// display jpg/jpeg image
     *header("Content-type: image/jpeg");
     *$im = imagecreatefromjpeg($imgs[$num]);
     *imagejpeg($im);
    	}elseif(strstr($imgs[$num], ".png")){
     *//display png image
     *header("Content-type: image/png");
     *$im = imagecreatefrompng($imgs[$num]);
     *imagepng($im);
    	}else{
     *die("ERROR2!!!");
    	}
    }else{
    	die("ERROR!!!");
    }
    
    ?>
    Simply call the script as an image.

    Example:
    http://wade.realestateleavenworth.com/wadesig.php

    Refresh it and it might change.

    Note: Animated gifs lose there animation and it stays on the first frame.
    Note2: IPB doesn't allow images with .php extentions so you can't you it for Invisionfree boards. Not sure about phpBB2 yet.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,178

    Default

    Yeah i seen this around, nice to see it on here though

    You wont get much comments on this tut because theres not a lot of PHP'ers on here

    Anyway thanks for the submission mate :P

  3. #3
    Join Date
    Sep 2005
    Location
    The Netherlands
    Posts
    553

    Default

    Tyvm man! Just what I needed for my website... Can you also add text to each image?

  4. #4
    Join Date
    Jan 2006
    Posts
    15

    Default

    Text gets a little tricky, but its possible. Not sure about fonts though.

  5. #5
    Join Date
    May 2005
    Posts
    275

    Default

    Very nice tut. It's a little bulky though. You might want to shorten the script up a little to make it actually worth using a script instead of images.

  6. #6
    Join Date
    Mar 2005
    Location
    Stockholm, Sweden
    Posts
    156

    Default

    Don't see why you're using GD though. :/ Just use readfile() to read the raw-contents of the file and send it with the appropiate header. Gifs and whatever will work fine. :/
    http://peksa.se - photos by me.

  7. #7

    Default

    There is a much simpler way of accomplishing the same thing using CSS.

    element.class{
    <?php $variable=rand(first number, number of images-first number);
    switch($variable)
    case number: echo 'background-image: url('url of one image');'; break;
    case number2: echo 'background-image: url('url of another image');'; break;
    ?>}

    element.class is a CSS thing, element is the page element (such as a div or span), class is a tag that is assigned to that element (as in &gtspan class="name"&lt. then you start the php tag inside of the CSS element (THIS CANNOT be inside of a .css document unless you've modified your server to parse CSS) <?php then we use the variable tag $name and we set that variable to equal a random number (1, 20) for example sets $name's value to be a random number between 1 and 20.
    then you call that value back with switch($name)
    then you use the cases to identify what each case should be (case 1: echo [echo tells the server to write this] 'background-image: url('url of one image');[closed the CSS tag]'[ends the echo];[ends the case] break;[ends one case and starts the next]

    div.head{

    <?php $bgi=rand(1, 10);
    switch($bgi)
    {case 1: echo 'background-image: url('/header/h1.gif');'; break;
    case 2: echo 'background-image: url('/header/h2.gif');'; break;
    case 3: echo 'background-image: url('/header/h3.gif');'; break;
    case 4: echo 'background-image: url('/header/h4.gif');'; break;
    case 5: echo 'background-image: url('/header/h5.gif');'; break;
    case 6: echo 'background-image: url('/header/h6.gif');'; break;
    case 7: echo 'background-image: url('/header/h7.gif');'; break;
    case 8: echo 'background-image: url('/header/h8.gif');'; break;
    case 9: echo 'background-image: url('/header/h9.gif');'; break;
    case 10: echo 'background-image: url('/header/h9.gif');'; break;
    ?>}

    I used that on my site to make a random header image.
    Last edited by MysticMentalist; 09-02-2006 at 01:50 PM.

  8. #8
    Join Date
    Jul 2005
    Posts
    5

    Default

    Quote Originally Posted by MysticMentalist
    div.head{

    <?php $bgi=rand(1, 10);
    switch($bgi)
    {case 1: echo 'background-image: url('/header/h1.gif');'; break;
    case 2: echo 'background-image: url('/header/h2.gif');'; break;
    case 3: echo 'background-image: url('/header/h3.gif');'; break;
    case 4: echo 'background-image: url('/header/h4.gif');'; break;
    case 5: echo 'background-image: url('/header/h5.gif');'; break;
    case 6: echo 'background-image: url('/header/h6.gif');'; break;
    case 7: echo 'background-image: url('/header/h7.gif');'; break;
    case 8: echo 'background-image: url('/header/h8.gif');'; break;
    case 9: echo 'background-image: url('/header/h9.gif');'; break;
    case 10: echo 'background-image: url('/header/h9.gif');'; break;
    ?>}
    that's a lot of code tbh you would be better off with

    div.head{

    <?php $bgi=rand(1, 10);
    echo "background-image: url('/header/h".$bgi.".gif');";
    ?>}

    be processed in about the 24th of the time

    and tbh using the GD module for a random image is pointless as hell, every web browser i've seen has the ability to grab the image tag out of the images raw data to know the type

    and anyway just use an apache conf file and throw the php into a file with an image ext so it's forum and xhtml safe

Similar Threads

  1. terrain generator
    By nosferatu in forum Digital Art
    Replies: 2
    Last Post: 12-15-2005, 01:34 PM
  2. Random Link Generator
    By NightStalker in forum Other Tutorials
    Replies: 4
    Last Post: 09-24-2005, 07:13 AM
  3. Random Image Generator
    By Void.x in forum Other Tutorials
    Replies: 12
    Last Post: 07-29-2005, 08:22 AM
  4. Error Message Generator
    By the_dude_of_darkness in forum The Void
    Replies: 8
    Last Post: 06-18-2005, 10:24 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
  •  
Powered by vBadvanced CMPS v4.1.1