Dashboard > RIFE > ... > Content management framework > Transformers
RIFE Log In | Sign Up   View a printable version of the current page.
Transformers


Added by Joshua Hansen, last edited by Joshua Hansen on Dec 09, 2006  (view change)
Labels: 
(None)


Example: PhotoScalingImageTransformer

PhotoScalingImageTransformer.java

This is an ImageContentTransformer which uses attributes short-edge-length and long-edge-length to scale an image. If the aspect ratio of all of your images is consistent (i.e. 4:3), the scaling factor should also be consistent.

This is useful where you want to, say, create thumbnails of all your photos. For example, when uploading a photo and setting the long-edge-width to 1024, both 1600x1200 images and 1200x1600 images will have a scaling factor of .64. If the existing width attribute were used instead, these images would have scaling factors of .64 and .85, respectively – probably not what you expected.

The example bean and corresponding meta data are also included in the javadoc for the class.

public class MyBean {
	
	private int	id = -1;
	private byte[]  image = null;

	public int getId() { return id; }
	public void setId(int id) { this.id = id; }

	public byte[]	getImage() { return image; }
	public void	setImage(byte[] image) { this.image = image; }
	public void	setImageThumbnail(byte[] imageThumbnail) { }  // dummy setter 
	public byte[]	getImageThumbnail() { return image; }
}

 
public class MyBeanMetaData extends MetaData {
	private static final PhotoScalingImageTransformer IMG_TRANSFORMER = new PhotoScalingImageTransformer();
	public void activateMetaData()
	{
		// Store the full-size image
		addConstraint(new ConstrainedProperty("image")
				.notNull(true)
				.file(true)
				.mimeType(MimeType.IMAGE_JPEG));

		// Store the image scaled down to have it's shortest edge be 74 pixels
		addConstraint(new ConstrainedProperty("imageThumbnail")
				.notNull(true)
				.file(true)
				.listed(true)
				.position(1)
				.editable(false)
				.mimeType(MimeType.IMAGE_JPEG)
				.contentAttribute("short-edge-length", 74)
				.transformer(IMG_TRANSFORMER)
		 );
	}
}

Requirements

Testing

This example was written on a system using:

  • Jetty 5.1.4+
  • rife-1.4-jdk15.jar
  • JDK 1.5

References

See also:

[top]



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators