Special methods

This group of methods is designed to perform special operations with data without interacting with other properties and methods of classes. The most part of such functions are static, and they are located in the core class "Service".

  • cutText($text, $length [, $end]) - trims a text to the required quantity of characters with keeping solid 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 passed in $length parameter
  • randomString($length) - returns a light random line in Latin in lower case
  • strongRandomString($length) - returns a strong random line in Latin in 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, returns a path to 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 watermark on the image you need to prepare the file preliminary (semi-transparent .png form 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 watermark is set on center, but 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 watermark 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);
    $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>';