Difference between revisions of "Image Manipulation"

(Created page with "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 ...")
 
 
Line 1: Line 1:
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.
+
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'''.<br/><br/>
  
===Adding watermarks to an existing image===
+
===Add Watermarks to an Existing Image===
cImageAddWaterMark accepts the following parameters  
+
cImageAddWaterMark accepts the following parameters:
  
 
*$imageFile : The path to the original image or background
 
*$imageFile : The path to the original image or background
Line 16: Line 16:
 
CFactory::load( 'helpers' , 'image' );
 
CFactory::load( 'helpers' , 'image' );
 
   
 
   
// Assume that we already know the following properties
+
// Assume that we already know the following properties:
 
$imageFile      = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_black.jpg';
 
$imageFile      = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_black.jpg';
 
$destinationFile = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_blak_watermark.jpg';
 
$destinationFile = JPATH_ROOT . DS . 'images' . DS . 'joomla_logo_blak_watermark.jpg';
Line 24: Line 24:
 
$watermarkHeight = 12;
 
$watermarkHeight = 12;
 
   
 
   
// Get the width and height of image first so we can calculate where to place the watermarks.
+
// Get the width and height of image first so we can calculate where to place the watermarks:
 
list($imageWidth,$imageHeight) = getimagesize($imageFile);
 
list($imageWidth,$imageHeight) = getimagesize($imageFile);
 
   
 
   
// Place water mark at the bottom right of the image
+
// Place water mark at the bottom right of the image:
 
$positionX      = ($imageWidth - $watermarkWidth);
 
$positionX      = ($imageWidth - $watermarkWidth);
 
$positionY      = ($imageHeight - $watermarkHeight);
 
$positionY      = ($imageHeight - $watermarkHeight);

Latest revision as of 01:35, 8 March 2013

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);