A vraptor-plugin to work better with jmagick a java wrapper of ImageMagick
Switch branches/tags
Nothing to show
Failed to load latest commit information.



A vraptor plugin to work with the native library ImageMagick (using jmagick)


Clone the project and run mvn install.
In your pom.xml:

- Because jmagick call the native ImageMagick  library on your machine, you'll need to install it
(on mac you can install it running the homebrew command: brew install imagemagick)

-After that download the latest jmagick source from svn running: svn co https://jmagick.svn.sourceforge.net/svnroot/jmagick jmagick
-Then run the following commands:
	./configure --with-java-home=/System/Library/Frameworks/JavaVM.framework/Versions/Current --with-magick-home=/usr/local/jmagick
	make all & make install
	ln -s /usr/local/lib/libJMagick-6.5.7.so /Library/Java/Extensions/libJMagick.jnilib
 -After that you should provide your jar to maven, in my case I used:


vraptor-magicker uses vraptor-environment to provide some configuration:

magicker.images_path -> path where you want to save the images
magicker.images.thumb.width ->  thumbnail width
magicker.images.thumb.height -> thumbnail height
magicker.images.medium.width -> medium width
magicker.images.medium.height -> medium height

getting image

- Supose you'll need to convert your image object to MagickImage object, to do that, you have four options:

	1.1 Using InputStream:
		InputStream stream = this.getClass().getResourceAsStream("caelum.png");
		MagickImage image = this.magicker.takeImageStream(stream).getImage();
	1.2 Using a byte array:
		byte[] bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("caelum.png"));
		MagickImage image = this.magicker.takeImageBytes(bytes).getImage();
	1.3 Using path:
		String path = this.getClass().getResource("caelum.png").getPath();
		MagickImage image = this.magicker.takeImagePath(path).getImage();
	1.4 Using vraptor UploadedFile
		UploadedFile file = aFile;

 - Resize an image:

		MagickImage image = this.magicker.takeImageStream(this.getClass().getResourceAsStream("caelum.png")).resizeTo(width, height).getImage();
 - Save original image and a thumbnail image:

 - Save original image and a medium sized image:

 - Save original and a custom sized image:

		this.magicker.takeImageStream(stream).withTitle(title).addCustom(500, 600).save();
 - Or you can save all:
		this.magicker.takeImageStream(stream).withTitle(title).addThumb().addMedium().addCustom(500, 600).save();
 - If you want to define other path
		this.magicker.takeImageStream(stream).withPath(path).withTitle(title).addThumb().addMedium().addCustom(500, 600).save();
 - Receiving the Magicker object:

		    public class MyController {

		        private Magicker magicker;

		        public MeuController(Magicker magicker) {
		            this.magicker = magicker;

		        public void saveImage(UploadedFile file) {
		            this.magicker.takeImageUploaded(file).addThumb().addMedium().addCustom(500, 600).save();


		Thumbnails will be saved in a sub-directory called thumb
		Medium images will be saved in a sub-directory called medium
		Custom sized images will be saved in a sub-directory called custom
		And you need to create them all, the library will not create them for you.