Jump to content

A dynamic image - almost there


mrbuter

Recommended Posts

Alright I have the dynamic image WORKING but the problem I guess is that it's a php file (durrrr)

 

If I wanted to link this image to a forum, it would not work because vBulletin protects from malicious php files as images (and thus not letting you make a php file an image).

 

Now with that said, I know that there must be some way to make an actual image extension file be dynamic because I've seen it done before with like...stats stuff. Like how many hours someone has played such and such game and it updates every day etc.

 

Is there any way I can do this? Can I set up some sort of alias called image.png that is actually image.php (points to it or something...)

 

 

btw here is my code (actually someone else made it, got it from these forums and modified it a bit)

 

<?php
function LoadJpeg($imgname)
{
    $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
    if (!$im) { /* See if it failed */
        $im  = imagecreatetruecolor(150, 30); /* Create a black image */
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
        /* Output an errmsg */
        imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
    }
    return $im;
}

header("Content-Type: image/jpeg");

$im = LoadJpeg("test.jpg"); // here is where you need to point to an existing image on which you need to write the text.



// Create the image
//$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$original = mktime(12, 5, 19, 1, 22, 2008);
  $today = time();
  $difference = $today - $original;

$text = "Day " . floor($difference / 84600) . " since last yelling on vent.";
$text2 = "Days since Artman was fired: " . floor($difference / 84600) . "";
// Replace path by your own font path
$font = 'Arial-Black-Italic.ttf';

// Add some shadow to the text
#imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

$transparentColor = imagecolorallocatealpha($im, 239, 240, 241, 241);
imagefill($im, 0, 0, $transparentColor);

// Add the text
imagettftext($im, 10, 0, 10, 20, $black, $font, $text);
imagettftext($im, 10, 0, 10, 40, $black, $font, $text2);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);


imagejpeg($img);
?> 

 

 

Link to comment
Share on other sites

Use .htaccess

 

Go to your WWW root, usually it looks like this -

path: /home/username/public_html

 

Look for the file named .htaccess. If it's not there, create a blank page using NotePad and save it as .htaccess

 

Now edit this file by adding the following lines:

 

RemoveHandler .jpg .jpeg
AddType application/x-httpd-php .php .jpeg .jpg

 

Save and close the .htaccess file. Upload it to your webserver (to your WWW root)

 

Now rename your script from image.php to image.jpg or image.jpeg.

and that should do it

:)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.