Image Manipulation

Manipulating images with JomSocial is pretty simple. You can just use one of the existing helper functions. Before you can begin using the helpers, you need to load the Image Helper Library.

Add Watermarks to an Existing Image

cImageAddWaterMark accepts the following parameters:

  • $imageFile : The path to the original image or background
  • $destinationFile : The path to the file that you want to save it to.
  • $imageType : Type of image whether a 'image/jpeg' , 'image/png' , 'image/gif'
  • $watermarkFile: The path to the watermark file
  • $positionX (optional): Allows you to specify the x position of the watermark in the image. Defaults to 0 if not specified.
  • $positionY (optional): Allows you to specify the y position of the watermark in the image. Defaults to 0 if not specified.

Example

// This is required to load the image helper
CFactory::load( 'helpers' , 'image' );
 
// Assume that we already know the following properties:
$imageFile       = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_black.jpg';
$destinationFile = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_blak_watermark.jpg';
$imageType       = 'image/jpeg';
$watermarkFile   = JPATH_ROOT . DS . 'images' . DS . 'sort_asc.png';
$watermarkWidth  = 12;
$watermarkHeight = 12;
 
// Get the width and height of image first so we can calculate where to place the watermarks:
list($imageWidth,$imageHeight) = getimagesize($imageFile);
 
// Place water mark at the bottom right of the image:
$positionX       = ($imageWidth - $watermarkWidth);
$positionY       = ($imageHeight - $watermarkHeight);
 
cImageAddWaterMark($imageFile,$destinationFile,$imageType,$watermarkFile,$positionX,$positionY);