Working with images


There are some new tools available in Seagull 0.6.2 for working with images. Currently Media module uses it's ablilities to process images after downloading files on server. The everyday tasks for image related processing after one is uploaded are:

  • fit image to certain size (not wider than XxY),
  • create thumbnail(s),
  • add watermark to authorize image source,
  • make all images same size like XxY filling the rest of canvas with some background color and positioning original image in the center (very useful when developing well-formed galleries opened in pop-up window),
  • applying borders (this can be also done with CSS, but we can reduce the mark-up),
  • and everything mentioned above at once.

Everything mentioned above is now available in Seagull.

Package structure


  • main library - Image.php (located in SGL_CORE_DIR)
  • transformations - ImageTransform directory, which contains transfomation files (located in SGL_CORE_DIR),
  • tests (located in SGL_CORE_DIR/tests):
    • ImageTest.ndb.php,
    • ImageConfigTest.ndb.php,
    • ImageTransformStrategyTest.ndb.php,
    • image.ini,
    • chicago.jpg,
  • GD_SGL.php - driver (located in SGL_LIB_PEAR_DIR/Image/Transform/Driver).


  • SGL_Image - main class, executes strategies, creates thumbnails etc,
  • SGL_ImageConfig - class for dealing with SGL_Image configuration i.e. parsing ini files, extracting strategy parameters from a string,
  • SGL_ImageTransformStrategy - abstract strategy, which is inherited by
    • SGL_ImageTranform_ResizeStrategy - resize strategy,
    • SGL_ImageTranform_AddImageStrategy - strategy for adding images across the original one,
    • SGL_ImageTranform_ColorOverlayStrategy - overlays image with color,
    • SGL_ImageTranform_AddBorderStrategy - strategy for adding border,
    • SGL_ImageTranform_CanvasResizeStrategy - strategy for resizing canvas,
  • Image_Transform_Driver_GD_SGL - driver, which extends some functionality of original GD driver supplied with PEAR::Image_Transform package.



Code examples



The main feature of image tools is an ability to transform specified image and it's thumbnails using the driver to perform this. The driver, which use five default strategies, is GD_SGL, but can be any other PEAR::Image_Transform can offer. In theory one image can be transformed by two different strategies using two different drivers e.g. with GD for resizing and with NetPBM for rotating. A developer can easily write his/her own extending SGL_ImageTransformStrategy abstract class.

Below is an example of the image transformed by all five currently available transformations:

  • original image was resized to certain size,
  • canvas was enlarged filled with specified background color,
  • performed color overlay (from right bottom corner),
  • watermark image was added,
  • applied border.