Skip to content

componentImageStorageServer

Sebastian Schlicht edited this page Oct 29, 2013 · 21 revisions

This component provides images and is responsible for all related works like analysing meta data, cropping and rotating images.

Requirements

  • [NewsStream] the image server should be able to provide a user avatar using a static page e.g. including the user's global key
  • [Fans] user self publication
  • [other Websites] providing content for external sites (image hosting/presentation)
  • [Venues] providing the possibility to host event pictures

new version

Since the Image Gallery has been nearly completed new requirements have established. Therefore the image server component has to be redesigned.

The basic image storage server will be embedded server deployed to Maven which can work with images in multiple ways. It may include methods we do not use but that are helpful for developers using the server.
The focus in this service is the general purpose.

Methods to create images

createImage

Basic way to create an image in the size passed.
An unused image identifier is needed. You can store meta data for the image optionally.
You can rotate the image according to its EXIF data optionally.
Returns a success flag being true if the creation was successful and false otherwise.

parameters:

  • imageIdentifier [String]: unused image identifier for the new image
  • image [InputStream]: input stream of the binary image, supporting all JMagick-supported formats installed (available for Ubuntu at least: GIF, JPEG, PNG, TIFF)
  • metaData [String]: JSON String containing optional meta data, checked if valid JSON only
  • autoRotate [boolean]: enables the optional auto rotation according to the EXIF information

createCroppedImage

Method to use only a certain frame of the image passed.
To specify this frame you need to pass cropping information.
Returns a success flag being true if the creation was successful and false otherwise.

parameters:

  • imageIdentifier [String]
  • image [InputStream]
  • metaData [String]
  • croppingInformation [ImageFrame]: cropping values will, checked if valid concerning the image

ImageFrame

  • left [int]: distance to left border specifying where the image begins
  • top [int]: distance to upper border specifying where the image begins
  • width [int]: width of the new image frame
  • height [int]: height of the new image frame

createImageFromUrl

Method to create an image in the size passed using an URL.
This URL has to be passed instead of an input stream.
Returns a success flag being true if the creation was successful and false otherwise.

parameters:

  • imageIdentifier [String]
  • imageUrl [String]: URL to the image that will be downloaded and stored, supporting all JMagick-supported formats installed
  • metaData [String]

Methods to read images

readOriginalImage

Method to read the original image uploaded once.
Returns the original file as it has been uploaded, before rotation and cropping has been appended.

parameters:

  • imageIdentifier [String]: image identifier used by an existing image

readImage

Read the basis image - compressed image including rotation and cropping.

parameters:

  • imageIdentifier [String]

readScaledImage

Read a scaled version of the basis image.
Returns an compressed image having the size specified or the basis image if the size requested was larger than the basis image.

parameters:

  • imageIdentifier [String]
  • width [int]: width of the new image frame
  • height [int]: height of the new image frame
  • scalingType [ScalingType]: specifies the way the image scaling should happen

ScalingType

  • FIT: downscale image until it fits in the frame
  • WIDTH: downscale image until its width matches the frame width
  • HEIGHT: downscale image until its height matches frame height

Methods to update an image

Note: You can not update an image itself but you can update the meta data stored.

updateImageMetaData

Updates the meta data stored for an image.
The JSON passed will be appended to the stored meta data, previous values will be overridden.
Returns a success flag being true if the update was successful and false otherwise.

parameters:

  • imageIdentifier [String]: image identifier used by an existing image
  • metaData [String]: JSON String containing the meta data that shall be appended, checked if valid JSON only

Methods to delete an image

deleteImage

Deletes the image specified.
Returns a success flag being true if the deletion was successful and false otherwise.

parameters:

  • imageIdentifier [String]: image identifier used by an existing image

Implementation details

The server stores images in their original version at least. If the image was cropped and/or rotated we will store the generated version and the cropping information in a database for retrievals. Each retrieval that provides an image size that is not existing yet will lead to a new image file having this dimension, as we assume the hard disk space wasted to be less expensive than the CPU time to compute the file to this dimension another time.
To compute the new version we use the basic JPEG image (already including our filters such as cropping and rotation).

We will hash the image identifiers to achieve a balanced directory tree.

So the directory tree will look like:

  • hash(image-id)[0..n]
  • basis [JPEG, may be cropped and/or rotated]
    • hash.jpg
  • 150x150
    • hash.jpg
  • 300x150
  • ...
  • originals
  • year of upload
    • day of upload
      • hash(user-id)[0..n]
        • hash

A database will hold the meta data of an image.

Features

Technologies

Responsible Developer

  • Christian
  • Sebastian
Clone this wiki locally