JMagick Tutorial

Learn how to download, install and create simple JMagick program through this tutorial.

JMagick Tutorial

JMagick Tutorial - Download, install and create simple program

JMagick library is Java library for handling the image in Java. It is implemented as thin Java Native Interface (JNI) layer to access the popular ImageMagick API. The ImageMagick API is written is C programming language. It is one of the most popular image handling library. ImageMagick  can be used to resize the image. It can also use to flip, mirror, rotate and even distort the input image. Beside these functionality it can also be used to shear and transform images.

Its import function includes adjustment of image colors, apply various special effects, or draw text etc... JMagick library allows you to perform these activity from the Java code also. In this tutorial I will teach you how you can use the JMagick library for manipulating the images.

Downloading and installing JMagick on windows

Step 1:  To Download the JMagick for windows operating system visit http://downloads.jmagick.org/6.3.9/.

Step 2: Download the file ImageMagick-6.3.9-0-Q16-windows-dll.exe and install on your computer. Add the installation path in the patch variable of your computer.

Step 3: Download jmagick-win-6.3.9-Q8.zip and unzip. The directory contains jmagick.jar and jmagick.dll.

Step 4: Add jmagick.jar is in the Java classpath.

Step 5: Copy jmagick.dll into jre\bin and JDK\lib directories

Now you can compile and run your program based on JMagick.

Example of JMagick that writes text on the image.

Blow is the program that writes the text on the image:

import java.io.*;
import java.awt.*;
import magick.*;

class InsertText
{
	public static void main(String a[]) throws IOException,MagickException
	{
		ImageInfo info=new ImageInfo("test.jpg");
		MagickImage image=new MagickImage(info);
		DrawInfo aInfo = new DrawInfo(info);
		aInfo.setFill(PixelPacket.queryColorDatabase("yellow"));
		//aInfo.setUnderColor(PixelPacket.queryColorDatabase("red"));

		aInfo.setOpacity(100);
		aInfo.setPointsize(36);
		aInfo.setFont("Arial");

		aInfo.setGeometry("+50+50");
		aInfo.setText("JMagick Tutorial");

		image.annotateImage(aInfo);
		image.setFileName("text.jpg");
		image.writeImage(info); 
	}

}

In this tutorial you have learned how to download, install and create simple program using JMagick library.

Tutorials

  1. JMagick Tutorial