Jump to content

Recommended Posts

Hello!

 

My personal website has a new banner each month for holiday themes. (I have a Christmas and Halloween banner, etc)

 

Right now, I have to manually switch out the picture each month.

 

Is there a free PHP code that would switch out the banner for me?  ???

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/50263-php-code-to-switch-out-banner-by-month/
Share on other sites

switch the link to the image to a php script with an image header and then on preset dates the script can point to different files

see below

 

 

EDIT: call this image.php and replace your banner.jpg with image.php

<?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");
$today = getdate();
switch($today['mon'])
{
default:
case 1:
$img = LoadJpeg("Jan.image.jpg");
break;
case 2:
$img = LoadJpeg("Feb.image.jpg");
break;
case 12:
$img = LoadJpeg("xmas.image.jpg");
break;
}
imagejpeg($img);
?> 

 

its a start :)

 

 

**UNTESTED

 

i guess this is free :P

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.