Click here to Skip to main content
12,350,610 members (24,632 online)
Click here to Skip to main content
Add your own
alternative version

Stats

55.4K views
1.5K downloads
15 bookmarked
Posted

ImageMagick Command Line Execution in ASP.NET

, 4 Jun 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Perform ImageMagick operations in ASP.NET using command line
magick_example.jpg magick_example2.jpg

Introduction

Some days ago, when I was going to do some image processing work, I stumbled over it. I needed to redraw an image using the data set by the user. Then I got ImageMagick. Now in ASP.NET, you will find very few articles or help for ImageMagick. Thanks to bubble2k for his excellent post on ImageMagick. But I decided to go for the command line execution of ImageMagick which is done easily in other web languages like PHP.

All the basic ImageMagick functionality that has been shown here is completely done by command line execution. 

Using the Code

Using the code is very easy. But you have to download the ImageMagick DLL version for windows from ImageMagick.org. Use the following link to download ImageMagick.

http://www.imagemagick.org/script/binary-releases.php#windows

Download ImageMagick-6.3.7-10-Q16-windows-dll.exe from the above link. Install the setup file. Your set up has been done. Now open the project using your editor.

***[Update] You can also check ImageMagick-6.5.3-Q16-windows.zip. It's the binary version of ImageMagick. Please follow the next * marked section for imagemagick binary use. 

Now here is the main matter that you should know to execute the EXE using command line:

Dim proc As New Diagnostics.Process()
proc.StartInfo.Arguments = fileargs
proc.StartInfo.FileName = Server.MapPath("MagickCMD.exe")
proc.StartInfo.UseShellExecute = False
proc.StartInfo.CreateNoWindow = True
proc.StartInfo.RedirectStandardOutput = False
proc.Start()

Now the MagicCMD.exe is the key which is executed every time using command line arguments. The command line arguments are passed using "fileargs" variable. Fileargs is written like this:

"convert " & Server.MapPath(source) & " -rotate 90 " & Server.MapPath(flname)

***[Update] Imagemagick Binary is more interesting. Download the imagemagick Binary from the above link. Unzip the folder, you can see that there are *.exe files for every possible imagemagick operators [like convert, compose, montage, etc.]. So you can use those operators directly in your application. Like to resize an image, you just need to write it in the following format:

convert -resize 500x200 C:\source.jpg C:\result.jpg
Then use the path in the following format. Check that here convert.exe has been used directly by the application.
Dim proc As New Diagnostics.Process()
proc.StartInfo.Arguments = fileargs
proc.StartInfo.FileName = Server.MapPath("magick\convert.exe")
proc.StartInfo.UseShellExecute = False
proc.StartInfo.CreateNoWindow = True
proc.StartInfo.RedirectStandardOutput = False
proc.Start()

The rest is the same. The command line only varies due to the various features. I have only used 12 features of imagemagick. There are many things that can be done. Visit the link below for more commands:

http://www.imagemagick.org/script/command-line-options.php#depth

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

arinhere
Web Developer
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionDealing with spaces in file paths Pin
Member 81458898-Jul-14 11:52
memberMember 81458898-Jul-14 11:52 
GeneralImageMagick Command Line Pin
Cameron Williams26-May-11 4:17
memberCameron Williams26-May-11 4:17 
GeneralRe: ImageMagick Command Line Pin
arinhere30-Jan-13 20:28
memberarinhere30-Jan-13 20:28 
QuestionWithout installing Pin
sachin.ims2-Jun-09 7:15
membersachin.ims2-Jun-09 7:15 
AnswerRe: Without installing Pin
arinhere2-Jun-09 19:03
memberarinhere2-Jun-09 19:03 
QuestionRe: Without installing Pin
sachin.ims3-Jun-09 4:21
membersachin.ims3-Jun-09 4:21 
AnswerRe: Without installing Pin
arinhere3-Jun-09 21:52
memberarinhere3-Jun-09 21:52 
GeneralRe: Without installing Pin
sachin.ims4-Jun-09 2:23
membersachin.ims4-Jun-09 2:23 
GeneralRe: Without installing Pin
arinhere4-Jun-09 18:53
memberarinhere4-Jun-09 18:53 
GeneralResize Pin
alurv5-Mar-09 19:56
memberalurv5-Mar-09 19:56 
GeneralRe: Resize Pin
arinhere5-Mar-09 20:28
memberarinhere5-Mar-09 20:28 
QuestionRe: Resize Pin
aakankshab20-Aug-10 2:11
memberaakankshab20-Aug-10 2:11 
AnswerRe: Resize Pin
arinhere20-Aug-10 4:15
memberarinhere20-Aug-10 4:15 
QuestionNot creat image in folder "convimg" Pin
huuchau844-Mar-09 0:10
memberhuuchau844-Mar-09 0:10 
AnswerRe: Not creat image in folder "convimg" Pin
arinhere4-Mar-09 0:20
memberarinhere4-Mar-09 0:20 
GeneralRe: Not creat image in folder "convimg" Pin
huuchau844-Mar-09 0:48
memberhuuchau844-Mar-09 0:48 
GeneralRe: Not creat image in folder "convimg" Pin
arinhere4-Mar-09 0:53
memberarinhere4-Mar-09 0:53 
GeneralRe: Not creat image in folder "convimg" Pin
huuchau844-Mar-09 16:03
memberhuuchau844-Mar-09 16:03 
GeneralUnable to run generate Thumbnails Pin
alurv2-Mar-09 23:12
memberalurv2-Mar-09 23:12 
GeneralRe: Unable to run generate Thumbnails Pin
arinhere4-Mar-09 0:24
memberarinhere4-Mar-09 0:24 
QuestionRe: Unable to run generate Thumbnails Pin
aakankshab20-Aug-10 2:19
memberaakankshab20-Aug-10 2:19 
AnswerRe: Unable to run generate Thumbnails Pin
arinhere20-Aug-10 4:42
memberarinhere20-Aug-10 4:42 
GeneralNot Working Fully with ASP.NET 2.0/VS2005 Pin
Gary Stafford23-Oct-08 6:06
memberGary Stafford23-Oct-08 6:06 
GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005 Pin
arinhere23-Oct-08 6:14
memberarinhere23-Oct-08 6:14 
GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005 Pin
Gary Stafford26-Oct-08 14:34
memberGary Stafford26-Oct-08 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 5 Jun 2009
Article Copyright 2008 by arinhere
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid