PHP code to "tag" an image as new

Discussion in 'PHP' started by trenttdogg, Feb 26, 2013.

  1. #1
    Is it possible (with PHP) to "tag" an image? The scenario is as follows:
    1) I add a new image to my website.
    2) The script automatically places a "banner" across that image that says "new"
    3) After 7 days the script automatically removes the "banner" from the image.

    Is this possible?
     
    trenttdogg, Feb 26, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    I'd check the file's date (filectime?), and add the 'new' banner in the markup, not to the actual image. Maybe a sibling span apo'd over the IMG tag.

    This is very rough/untested:
    define('SECONDS_AS_NEW',604800);
    
    $imageFile = 'test.png';
    $imageText = 'Describe the Image';
    $imageURL = 'images/'.$imageFile;
    $imagePath = 'images/'.$imageFile;
    /*
    	above $imagePath example assumes images is subdirectory of script
    	location - if not you might have to make $imagePath something like:
    	'/var/web/account/www/images/'
    */
    
    echo '
    	<span class="galleryImage">
    		<img src="',$imageURL,'" alt="',$imageText,'" />',(
    			(filectime($filename) > (time() - SECONDS_AS_NEW)) ?
    			'<span></span>' :
    			''
    		),
    	</span>';
    Code (markup):
    The inner span would only be included when the item is 'new', so your css to show it is simply to apo it off span.galleryImage with your 'new' image on it as a background.
     
    deathshadow, Feb 26, 2013 IP