Extension:ImageFooter

From MediaWiki.org

Jump to: navigation, search


         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
ImageFooter

Release status: beta

Description Adds a text footer at the bottom of the image uploaded
Author(s)  VolodyA! V Anarhist (Beta_MTalk)
Last Version  '0.1'
License GPL v 3
Download no link

check usage (experimental)

Contents

[edit] What can this extension do?

The intent of this extension is to add the footer to every uploaded image (only image types supported by GD will actually work do that).

[edit] Usage

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/ImageFooter/ImageFooter.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php. Search the web for the font FreeSansBold.ttf and upload it in $IP/extensions/ImageFooter/

[edit] Installation

To install this extension, add the following to LocalSettings.php:

require_once( "$IP/extensions/ImageFooter/ImageFooter.php" );
$wgImageFooterString='Some string'; // what string will be written on the image
$wgImageFooterOffset= array('up' => 9, 'left' => 180); // offset from the bottom right corner

[edit] Configuration parameters

  • $wgImageFooterString – this is any string which will be written onto the image. Default is equivalent to $wgSitename.
  • $wgImageFooterOffest – this is an array of 2 elements 'up' and 'left' specifying the offset from the bottom right corner of the image to start writing the string.

[edit] Code

<?php
 
// Released under GPLv3
 
if ( ! defined( 'MEDIAWIKI' ) ) die();
 
if ( is_null($wgImageFooterString) || $wgImageFooterString=='' ) $wgImageFooterString=$wgSitename;
 
// Setting up information for Special:Version page
$wgExtensionCredits['media'][] = array(
  'name' => 'Image Footer',
  'author' =>'VolodyA! V Anarhist',
  'url' => 'http://eng.anarchopedia.org/User:Beta_M',
  'version' => '0.1',
  'description' => 'Adds a footer to every image that is uploaded.'
  );
 
$wgHooks['UploadVerification'][] = array('fnImageFooterHook1');
 
function fnImageFooterHook1($saveName, $tempName, &$error)
{
  global $IP, $wgImageFooterString, $wgImageFooterOffset;
  echo $wgImageFooterOffset['left'];
  if(list($width, $height, $type, $attr) = getimagesize($tempName))
  {
 
 
    if(!imagecreatefromtype($tempName, $type, $img))
    {
      $error = 'Unable to open the file in ImageFooter extension, type is '.$type.' img is '.$img;
      return false;
    }
 
    $black = imagecolorallocate($img, 0, 0, 0);
    imagettftext($img, 12, 0, $width-$wgImageFooterOffset['left'], $height-$wgImageFooterOffset['up'], $black, $IP.'/extensions/ImageFooter/FreeSansBold.ttf', $wgImageFooterString);
 
    unlink($tempName);
    if(file_exists($tempName))
    {
      $error = 'File '.$tempName.' exists';
      return false;
    }
 
    if(!imagesavebytype($img, $tempName, $type))
    {
      $error = 'Error saving file';
      return false;
    }
  }
  else // probably not even an image
  {
    return true;
  }
  return true;
}
 
// opens an image regardless of the type
function imagecreatefromtype($file, $type, &$img)
{
  switch($type)
  {
    case IMG_GIF: // gif
      $img = imagecreatefromgif($file);
      break;
    case IMG_JPG: // jpeg
      $img = imagecreatefromjpeg($file);
      break;
    case IMG_PNG: // png
      $img = imagecreatefrompng($file);
      break;
    case IMG_WBMP:// wbmp
      $img = imagecreatefromwbmp($file);
      break;
    case IMG_XPM:// xbm
      $img = imagecreatefromxbm($file);
      break;
    default:
      return false;
      break; // for posterity only
  }
  return true;
}
 
// saves an image regardless of the type
function imagesavebytype($img, $file, $type)
{
  switch($type)
  {
    case IMG_GIF: // gif
      return imagegif($img, $file);
    case IMG_JPG: // jpeg
      return imagejpeg($img, $file);
    case IMG_PNG: // png
      return imagepng($img, $file);
    case IMG_WBMP:// wbmp
      return imagewbmp($img, $file);
    case IMG_XPM:// xbm
      return imagexbm($img, $file);
  }
  return false;
}