Click here to Skip to main content
6,595,854 members and growing! (18,176 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General License: The Code Project Open License (CPOL)

ImageMagick Command Line Execution in ASP.NET

By arinhere

Perform ImageMagick operations in ASP.NET using command line
VB (VB 7.x, VB 8.0, VB 9.0, VB 6), .NET (.NET 2.0), ASP.NET
Version:8 (See All)
Posted:14 Jan 2008
Updated:4 Jun 2009
Views:14,180
Bookmarked:9 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
4 votes for this article.
Popularity: 1.53 Rating: 2.54 out of 5
1 vote, 25.0%
1

2

3

4
3 votes, 75.0%
5
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)

About the Author

arinhere


Member

Occupation: Web Developer
Location: India India

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 25 (Total in Forum: 25) (Refresh)FirstPrevNext
QuestionWithout installing Pinmembersachin.ims8:15 2 Jun '09  
AnswerRe: Without installing Pinmemberarinhere20:03 2 Jun '09  
QuestionRe: Without installing Pinmembersachin.ims5:21 3 Jun '09  
AnswerRe: Without installing Pinmemberarinhere22:52 3 Jun '09  
GeneralRe: Without installing Pinmembersachin.ims3:23 4 Jun '09  
GeneralRe: Without installing Pinmemberarinhere19:53 4 Jun '09  
GeneralResize Pinmemberalurv20:56 5 Mar '09  
GeneralRe: Resize Pinmemberarinhere21:28 5 Mar '09  
QuestionNot creat image in folder "convimg" Pinmemberhuuchau841:10 4 Mar '09  
AnswerRe: Not creat image in folder "convimg" Pinmemberarinhere1:20 4 Mar '09  
GeneralRe: Not creat image in folder "convimg" Pinmemberhuuchau841:48 4 Mar '09  
GeneralRe: Not creat image in folder "convimg" Pinmemberarinhere1:53 4 Mar '09  
GeneralRe: Not creat image in folder "convimg" Pinmemberhuuchau8417:03 4 Mar '09  
GeneralUnable to run generate Thumbnails Pinmemberalurv0:12 3 Mar '09  
GeneralRe: Unable to run generate Thumbnails Pinmemberarinhere1:24 4 Mar '09  
GeneralNot Working Fully with ASP.NET 2.0/VS2005 PinmemberGary Stafford7:06 23 Oct '08  
GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005 Pinmemberarinhere7:14 23 Oct '08  
GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005 PinmemberGary Stafford15:34 26 Oct '08  
QuestionExit code 4 when I try to use convert Pinmembernst8884:02 22 Sep '08  
AnswerRe: Exit code 4 when I try to use convert Pinmemberarinhere4:28 22 Sep '08  
GeneralI just solved long problem in image processing using the exe version of ImageMagick Pinmemberkhan729023:22 3 Sep '08  
GeneralRe: I just solved long problem in image processing using the exe version of ImageMagick Pinmemberarinhere23:59 3 Sep '08  
GeneralNot working in Asp.net Pinmembersezhian_vertical0:55 2 Jul '08  
GeneralRe: Not working in Asp.net Pinmemberarinhere1:17 2 Jul '08  
Generalwidth of the page is exceeding the limit Pinmembernirosh_champika1230:40 16 Jan '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Jun 2009
Editor: Deeksha Shenoy
Copyright 2008 by arinhere
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project