Click here to Skip to main content
Email Password   helpLost your password?
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
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionWithout installing
sachin.ims
8:15 2 Jun '09  
Hi,

Nice post!

I tried to use this in my project. But there is a problem, I can't install anything on server(while deploying my project). So is it possible to achieve the task without installing the ImageMagick exe?

Any help will be appreciated.

Thanks,
Sachin
AnswerRe: Without installing
arinhere
20:03 2 Jun '09  
Hello sachin,

Please check out the ***[update] section. I have updated the article. You can try imagemagick Binary version without installation [though I haven't tried it, but I think it should work]. But make sure that you have provided proper permission to your application.

Thanks and Regards - Arin


P.S: Rate this article if it helps you.

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

QuestionRe: Without installing
sachin.ims
5:21 3 Jun '09  
yes it works, but the problem is that it doesn't work when I uninstall the imageMagick...
Is there any way arround to copy some dlls into project folder and make the application work?
AnswerRe: Without installing
arinhere
22:52 3 Jun '09  
If you want to use some basic operations of imagemagick then use magicknet.dll....but for more complex application follow as the instruction provided...

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralRe: Without installing
sachin.ims
3:23 4 Jun '09  
Thanks for you reply.

I just want to use convert function(from one image format to other). Can you please let me know where can I found magicknet dll. It would be great help.

Thanks,
Sachin
GeneralRe: Without installing
arinhere
19:53 4 Jun '09  
Hello Sachin,

I have uploaded the MagickNet.dll with the article...please check this out and download it as you need.

and the following is the process to convert

MagickNet.Magick.Init()
Dim img As MagickNet.Image = New MagickNet.Image(source_file)
Dim sz As New System.Drawing.Size(150, 100)
img.Resize(sz)

img.Write(output_file)
MagickNet.Magick.Term()

Let me know if you have any more queries...

Thanks

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralResize
alurv
20:56 5 Mar '09  
Hi,

I have used the below syntax to resize the image, but it is giving error

C:\>convert C:\GenerateThumb\images\DSCN5: -resize "200%" C
:\GenerateThumb\images\DSCN5.gif


convert: unable to open image `C:\GenerateThumb\images\DSCN5:': No such file or
directory @ blob.c/OpenBlob/2427.
convert: missing an image filename `C:\GenerateThumb\images\DSCN5.gif' @ convert
.c/ConvertImageCommand/2766.

Would you please provide me the syntax and example for resizing an gif file using MagickCMD.exe

--Thanks & regards
Veeresh
GeneralRe: Resize
arinhere
21:28 5 Mar '09  
Hello,

"C:\GenerateThumb\images\DSCN5:" -- This is your provided imagepath...and I am not sure what kind of image that would be. There must be some extension for the image.
So please make sure of that.

One more thing. If you have installed imagemagick on your local system, then you can also check these command from command prompt...it will work

and here is the code for resizing

convert -resize 200% D:\tom-cruise.jpg D:\katie.png

Let me know if you have any more queries

Thanks

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

QuestionNot creat image in folder "convimg"
huuchau84
1:10 4 Mar '09  
I am user the code, but when run in folder "convimg" empty -Not creat image in folder "convimg"
Please help me!
Thanks!!!Confused
huuchau84
AnswerRe: Not creat image in folder "convimg"
arinhere
1:20 4 Mar '09  
Hello huuchau84,

Make sure about the permission before executing the code as you are using an exe in the server. So you must provide full permission to it. Provide ASPNET permission to your application and check out the path of imagemagick. Once you confirm about it, I am sure that it will run.

Let me know if you have any more queries.

Thanks - Arin

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralRe: Not creat image in folder "convimg"
huuchau84
1:48 4 Mar '09  
Thanks arinhere!!
I am user windowserver 2003 --> problems??
thanhs for Re!!!
GeneralRe: Not creat image in folder "convimg"
arinhere
1:53 4 Mar '09  
nop....no problem at all....just use your remote desktop for server....locate the application folder->right click->security tab->add->advanced->find now->ASPNET->OK->in the permission section below select checkbox for all

and you are done...

If still you are facing the same...then let me know

Thanks

P.S: pleas rate this article if its help you

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralRe: Not creat image in folder "convimg"
huuchau84
17:03 4 Mar '09  
Thank you so much!!! Smile
GeneralUnable to run generate Thumbnails
alurv
0:12 3 Mar '09  
Hi,

By using your sample application I have created application, where it will create thumbnail
I had requirement to generate a thumbnails in file server

In local application is able to generate thumbnails
When I am trying create thumbnail on file server it is not generating

Requirement:-
Applications server
File server

Application has to generate thumbnails of the file which is located in File server and store it in that file server


I am using impersonation to connect to the File server, I am able to check whether the file exists or not, and I am able to create file. but by using MagicCMD.exe I am not able to create thumbnails

Would you please help me to solve this problem
GeneralRe: Unable to run generate Thumbnails
arinhere
1:24 4 Mar '09  
Hello alurv,

Most of the time we have faced this kind pf thing, is occurred because of permission. You have said about the problem but you haven't mentioned anything about the permission. Did you provide ASPNET permission to your application? As you have told, the application is running fine in your local system. So please check out permission level in the server. If you didn't provide ASPNET permission to your application then
please provide it, it will work.

Let me know if you have any more queries.

Thanks - Arin

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralNot Working Fully with ASP.NET 2.0/VS2005
Gary Stafford
7:06 23 Oct '08  
Thank you for your posting, ImageMagick is very helpful. I installed your source files and ran the application. I can see the dropdown options and the default image. However, when select an option, the default image vanishes and nothing else happens, no errors, or anything. Has anyone else experienced this? Is there something else I need to download and install. I thought I had ImageMagick installed properly. Do I need to add a reference to that dll? Thank you in advance.

Regards,

Gary

GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005
arinhere
7:14 23 Oct '08  
Hello Gary,

I have used ImageMagick successfully on server. First download and istall imagemagick on your server. You will find a exe file[MagickCmd.exe] in the imagemagick installation folder. Copy that exe and place it in your application folder. remember to provide ASPNET permission to your application and use imagemagick as I mentioned in the application. It will work.

Rate this post if it helps.

Thanks

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralRe: Not Working Fully with ASP.NET 2.0/VS2005
Gary Stafford
15:34 26 Oct '08  
Arin:
Thank you for your reply. I solved my problem; it was a sharing problem. I needed modify security to give the ASP.NET Machine Account read/write access to the files so they could be modified/written/read by ASP.NET Machine Account.

Gary

Regards,

Gary

QuestionExit code 4 when I try to use convert
nst888
4:02 22 Sep '08  
Hi,

I'm running the source code you have kindly downloaded but whenever I try to run any command I am getting an exit code of 4. I cannot seem to find a description of this exit code anywhere and am a bit stuck.

I have not amended any of your code - that is exactly what I'm running.

My OS is windows XP - not sure if this makes any difference.

Kind regards,
Nicki
AnswerRe: Exit code 4 when I try to use convert
arinhere
4:28 22 Sep '08  
Hello Nicki,

Can you provide the exact error you have got? Actually I didn't get what your problem is? So it will be better for me to suggest you something if you provide me the exact error you have got, and the steps you have followed starting from the installation of imagemagick.

Thanks and Regards - Arin

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralI just solved long problem in image processing using the exe version of ImageMagick
khan7290
23:22 3 Sep '08  
There is no asp.net dll version of ImageMagick that works smoothly.
Some folks tried to create a dll for .net version but I was never able to make it work.

Thanks for this article. It was really a big help. Thanks to guys who created ImageMagick!!

The exe version is pretty fast and very versatile.
We can have the commands in config file and avoid recompilation if we need to change the command. Awesome!
GeneralRe: I just solved long problem in image processing using the exe version of ImageMagick
arinhere
23:59 3 Sep '08  
thanks for the comment Big Grin

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

GeneralNot working in Asp.net
sezhian_vertical
0:55 2 Jul '08  
The example given is not working in asp.net.When we exceute the "convert" function in the application ,we are not geting images in the output folder.

Please provide us a working example.

email id: anand@sdi.la

Thanks,
Anandhavel.J

sezhi

GeneralRe: Not working in Asp.net
arinhere
1:17 2 Jul '08  
please let me know ur problem in details....I'll help u as far as I can...

write to me at arinhere@gmail.com

Arin
Mail: arinhere@gmail.com
http://blogs.msdn.com/coding4fun/archive/2008/04/16/8399645.aspx

Generalwidth of the page is exceeding the limit
nirosh_champika123
0:40 16 Jan '08  
Please check it and update again..


Last Updated 5 Jun 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010