ImageTools Class

Example Page

Se all operations performet by class ImageTools

Exmaple no. 1

Image effects: Reflecting an image

  • Original
    Original
  • After
  • PHP
    <?php
    $img = new ImageTools("example_img/flower.jpg");
    $img
    ->reflect(35, "#EBEBEB", 1); // drop shadow percentage, background color, spacing
    $img
    ->showImage();
    $img
    ->destroy(); // Deallocate reserved memory space while transforming image (always callt this method on the end after image work)
    ?>

Exmaple no. 2

Image effects: Grayscale Image

  • Original
    Original
  • After
  • PHP
    <?php
    $img = new ImageTools("example_img/flower.jpg");
    $img
    ->grayscaleImage(); // Grayscale
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 3

Image effects: Brightening and Contrasting

  • Original
    Original
  • After
    Brightness
    Contrast
  • PHP
    <?php
    // Brightening
    $img =
    new ImageTools("example_img/sunset.jpg");
    $img
    ->setBrightness(30); // Brightening image for value 30
    $img
    ->showImage();
    $img
    ->destroy();

    // Contrasting
    $img =
    new ImageTools("example_img/sunset.jpg");
    $img
    ->setContrast(-20); // Contrasting image for value minus 20
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 4

Image effects: Blur and Gaussian blur

  • Original
    Original
  • After
    Simple blur
    Gaussian blur
  • PHP
    <?php
    // Simple Blur
    $img =
    new ImageTools("example_img/sampletext.jpg");
    $img
    ->addBlur(); // bluring
    $img
    ->showImage();
    $img
    ->destroy();

    // Gaussian Blur
    $img =
    new ImageTools("example_img/sampletext.jpg");
    $img
    ->addGaussianBlur(); // bluring
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 5

Resizing: Rize by original size of image

  • Original
    Original
  • After
    Resizing original image to 300x200 pixels
  • PHP
    <?php
    // Simple Blur
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeOriginal(300,200); // new width, new height
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 6

Resizing: Rize by specified width or height

  • Original
    Original
  • After
    Resizing image width to 200 pixles
    Resizing image height to 200 pixles
  • PHP
    <?php
    // Resize image by specified width
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeWidth(200); // new width
    $img
    ->showImage();
    $img
    ->destroy();

    // Resize image by specified height
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeHeight(200); // new height
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 7

Resizing: Resize image by specified width (height) and center it on new width and height

  • Original
    Original
  • After
    Create 200x200 image and resize original image width to 215 pixels
    Create 100x100 image and resize original image height to 315 pixels
    Create 300x300 image and resize original image height to 150 pixels
  • PHP
    <?php
    // Create new image and resize original image by specified width
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeNewByWidth(200,200,215,"#CCC"); // new width, new height, new resize width, bg color
    $img->setOutputType(ImageTools::IMAGE_TYPE_PNG);
    // output result image as PNG
    $img
    ->showImage();
    $img
    ->destroy();

    // Create new image and resize original image by specified height
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeNewByHeight(100,100,215,"#CCC"); // new width, new height, new resize height, bg color
    $img->setOutputType(ImageTools
    ::IMAGE_TYPE_PNG); // output result image as PNG
    $img
    ->showImage();
    $img
    ->destroy();

    // Create new image and resize original image by specified height
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->resizeNewByHeight(300,300,150,"#CCC"); // new width, new height, new resize height, bg color
    $img->setOutputType(ImageTools::IMAGE_TYPE_PNG);
    // output result image as PNG
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 8

Watermarking: Text watermark on image, 9 different positions and 4 different options on text (text size, color, angle, margin)

  • Original
    Original
  • After
    Applying watermark text on all positions

    You can apply these attributes to watermark text (on the right order):
    • Watermark text on the image
    • Vertical position (top, center, bottom)
    • Horizontal position (left, center, right)
    • Font size (default 12)
    • Font color in hexadecimal format (default white)
    • Angle to rotate text (default 0°)
    • Margin text from near corner (default 5 pixels)

    Font pack used on this example is Arial.ttf (TrueType) that can be found on fonts/ directory, and you can change it depending on your font prefferences

    Top-Left: font-size:18, color:#FFF, angle=0, margin=5
    Top-Center: font-size:14, color:#CCC, angle=0, margin=2
    Top-Right: font-size:20, color:#FF0000, angle=12, margin=10
    Center-Left: font-size:12, color:#336600, angle=0, margin=0
    Center-Center: font-size:18, color:#CCC, angle=90, margin=0
    Center-Right: font-size:20, color:#0066CC, angle=12, margin=10
    Bottom-Left: font-size:18, color:#FFF, angle=0, margin=5
    Bottom-Center: font-size:14, color:#CCC, angle=0, margin=2
    Bottom-Right: font-size:20, color:#66FF00, angle=12, margin=10

  • PHP
    <?php

    /**
      * Constats for positioning text can found on ImageTools.interface.php
      * Example of using those constants:
      * ImageToos::CONSTANT_NAME - where CONSTANT_NAME is the constant you want to use
     */


    // Applying 9 text watermarks on the image

    $img =
    new ImageTools("example_img/flower.jpg");

    $img->addWatermark("Top-Left", ImageTools::IMAGE_POSITION_TOP, ImageTools::IMAGE_POSITION_LEFT, 18, "#FFF", 0, 5);
    // Top Left

    $img->addWatermark("Top-Center", ImageTools::IMAGE_POSITION_TOP, ImageTools::IMAGE_POSITION_CENTER, 14, "#CCC", 0, 2);
    // Top Center

    $img->addWatermark("Top-Right", ImageTools::IMAGE_POSITION_TOP, ImageTools::IMAGE_POSITION_RIGHT, 20, "# FF0000", 12, 10);
    // Top Right

    $img->addWatermark("Center-Left", ImageTools::IMAGE_POSITION_CENTER, ImageTools::IMAGE_POSITION_LEFT, 12, "# 336600", 0, 0); // Center Left

    $img->addWatermark("Center-Center", ImageTools::IMAGE_POSITION_CENTER, ImageTools::IMAGE_POSITION_CENTER, 18, "#CCC", 90, 0);
    // Center Center

    $img->addWatermark("Center-Right", ImageTools::IMAGE_POSITION_CENTER, ImageTools::IMAGE_POSITION_RIGHT, 20, "#0066CC", 12, 10);
    // Center Right


    $img->addWatermark("Bottom-Left", ImageTools::IMAGE_POSITION_BOTTOM, ImageTools::IMAGE_POSITION_LEFT, 18, "#FFF", 0, 5); // Bottom Left

    $img->addWatermark("Bottom-Center", ImageTools::IMAGE_POSITION_BOTTOM, ImageTools::IMAGE_POSITION_CENTER, 14, "#CCC", 0, 2); // Bottom Center

    $img->addWatermark("Bottom-Right", ImageTools::IMAGE_POSITION_BOTTOM, ImageTools::IMAGE_POSITION_RIGHT, 20, "#66FF00", 12, 10); // Bottom Right

    $img->setOutputType(ImageTools::IMAGE_TYPE_PNG);
    // Output result image as PNG file
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 9

Watermarking: Add watermark image to image

  • Original
    Original
  • After
    Applying watermark image on the bottom-right of the image (there is no need to illustrate on other positions watermark because it is explained in the above example)
  • PHP
    <?php
    // Resize image by specified width
    $img =
    new ImageTools("example_img/sunset.jpg");
    $img
    ->addWatermarkImage("example_img/watermark.png", ImageTools::IMAGE_POSITION_BOTTOM, ImageTools::IMAGE_POSITION_RIGHT, 5); // Image path, vertical position, horizontal position, margin from corners
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 10

Cropping Image: Crop image on specified x,y coordinate and specified width,height

  • Original
    Original
  • After
    Cropping image starting at X:50, Y:150 and set Width:100, Height:340
  • PHP
    <?php
    // Cropping Image
    $img =
    new ImageTools("example_img/kasparov.jpg");
    $img
    ->cropImage(50,150,100,340); //x pos, y pos, width, height
    $img
    ->showImage();
    $img->setOutputType(ImageTools::IMAGE_TYPE_GIF); // Output result image as GIF file
    $img
    ->destroy();
    ?>

Exmaple no. 11

Transparent Images: Working with transparent images

  • Original
    Original
  • After
    Importing image with transparent area (no other actions)

    Importing image with transparent area (calling $im->setTransparentBg())
  • PHP
    <?php
    // Transparent image
    $img =
    new ImageTools("example_img/sampleimpg.png");
    $img
    ->setTransparentBg(); //set transparent background
    $img
    ->showImage();
    $img
    ->destroy();
    ?>

Exmaple no. 12

Outputting Image: Saving image

  • PHP
    <?php

    /**
      * Dont forget that ImageTools save() function can called on every image action but it will needed to
      * be above the $im->destroy() function, even if you output image to the browser and saving it
       * concurrently, this serves also for $im->showImage() function
      */

    // Saving image

    $img =
    new ImageTools("example_img/sunset.jpg");

    $img
    ->save("/tmp/", "myimage.jpg", 95, true); // path to save image, image name, image quality (if it is JPG format otherwise you can set this parameter 0), overwrite (or not) existing file (with the same name)

    $img->showImage();
    // This image is saved on the disk but this function doesn't require disk reference (slower) it only references on memory (quicker)

    $img
    ->destroy();
    ?>
You can buy this class exclusively at Envato Marketplace
© Author: Arlind Nushi <[email protected]>