Special Methods

This group of methods is designed to perform one-time operations with data without interacting with other properties and methods of classes. The most part of such functions - are static an they are located in the class Service.

  • cutText($text, $length [, $end]) - trim the text to the required quantity of characters with keeping the last word. It is possible to pass a string value as an optional parameter which will be added to the trimmed text the source text is longer than the value of $length
  • randomString($length) - returns a random line in Latin in the lower case
  • addFileRoot($path) - adds a root of file system to the file, $path shall begin from a project root, without initial "/" (usually "userfiles/models/")
  • removeFileRoot($path) - removes a root of file system, leaving a path to the file from a project root without initial "/"
  • getExtension($file) - returns a file extension (without dot)
  • removeExtension($file) - returns a path value of the file without extension

Examples of using methods of the class Service.

echo Service :: cutText($text, 200, "...");
echo Service :: randomString(7);

Apply a watermark on the Image

To apply a water mark on the image you need to prepare the file preliminary (semi-transparent .png forma is preferrable ). The file can be placed in the "media/images/" folder. Further when creating thumb of the image you need to pass parameters as shown on examples below. By default, the water mark is set on center, thus you can move it using the following parameters:

  • "watermark-margin-top" - an indent from the upper edge
  • "watermark-margin-right" - an indent from the right edge
  • "watermark-margin-bottom" - an indent from bottom edge
  • "watermark-margin-left" - an indent from the left edge

Attention! If thumb copies for images have been already created earlier (after calling cropImage or resizeImage methods), then you need to delete them, after that new images will have a water mark set.

//Apply a watermark to thumb copy of image  in model class 
$image_params = array("watermark" => "media/images/watermark.png");
$image = $this -> cropImage($this -> getFirstImage($row['images']), 250, 250, $image_params);
 
//Apply a watermark with shifting
$image_params = array("watermark" => "media/images/watermark.png", 
                      "watermark-margin-right" => 10, 
                      "watermark-margin-top" => 10);
$image = $this -> resizeImage($this -> getFirstImage($row['images']), 250, 250, $image_params);
 
//Apply a watermark with centering 
$image_params = array("watermark" => "media/images/watermark.png", "watermark-center-position" => true);
$image = $this -> cropImage($this -> getFirstImage($row['images']), 170, 170, $image_params);

//Apply a watermark on the first image of gallery for lightbox 
if($product -> images)
{
    $image = $product -> getFirstImage("images"); 
    $image_params = array("watermark" => "media/images/watermark.png", "only-source" => true,
                          "watermark-margin-left" => 5, "watermark-margin-bottom" => 5);
 
    $image_source = $mv -> products -> resizeImage($image, 1200, 1200, $image_params);
    unset($image_params["only-source"]);
    $image_params["alt-text"] = $product -> name;
 
    echo '<a class="fancybox" rel="group" href="'.$image_source.'">';
    echo $mv -> products -> resizeImage($image, 340, 280, $image_params);
    echo '</a>';
}