Link to home
Create AccountLog in
Avatar of hrolsons
hrolsonsFlag for United States of America

asked on

Using ImageMagick to create a thumbnail, through VB6

I use the following command to successfully convert a .tif file to a .jpg file:

ShellAndWait "C:\Program Files\ImageMagick-6.7.2-Q16\Convert.exe logo.tif logo.jpg", , 60

Does anyone know how I could do something similar to create a thumbnail with the longest side being 150px?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I use imagemagick as a com object for classic asp.  Can you see how to covert what I did for your vb6?

This is the code I use to resize to a width of 500 and 200 for web which is why the quality is set to 50.  The last line creates a thumb that zooms in a little and centers the image as it zooms.
The greater then sign means only make it smaller and not larger.

Set Img = Server.CreateObject("ImageMagickObject.MagickImage.1") 
thepic=' uploaded image

img.Convert sourcefolder&thepic,"-quality","50","-resize","500>",  savefolder_med&thepic
img.Convert sourcefolder&thepic,"-quality","50","-resize","200>",  savefolder_small&thepic
img.Convert "-define", "jpeg:size", "200x200", sourcefolder&thepic,"-thumbnail", "100x100^", "-gravity", "center", "-extent", "100x100" , savefolder_thumb &"thumb"&thepic

Open in new window

Avatar of hrolsons


So in my command line above, does the 60 represent quality.  I want the best quality, which would be 100 I assume.  It looks like I need to add to the command line: "-resize","150"
That sounds right or I think you can leave quality blank but setting it to 100 sounds like a good idea.
I'm not sure where the 60 came from, because I would never have done 60% quality.  That was a few years ago so I can't remember now.
I don't know about the command line since I don't use it but it looks like the info is here 

If you leave it off, I would think the default is 100%
I looked at ShellAndWait:

Public Sub ShellAndWait(ByVal program_name As String, _
                         Optional ByVal window_style As VbAppWinStyle = vbNormalFocus, _
                         Optional ByVal max_wait_seconds As Long = 0)

So the 60 was simply "max_wait_seconds".  OK, back on topic.  I'll see if I can get "-resize","150"  to work after my son's baseball game tonight.
I've requested that this question be deleted for the following reason:

Ok, your last comment was you would look at it. I never  heard back.  Good luck.
Oh, you're totally right.  Silly me!!!
Still working on it.
I'm afraid "-resize" is going to resize the original.  I need to keep the original.  Perhaps I'll copy the original and then resize the copy.
Your objectives are

convert a .tif file to a .jpg file
create a thumbnail with the longest side being 150px

It sounds like you want something different.  Look at my original sample.  The first two lines resize.  Using the > sign means only resize if larger.    If your image is 100 and you use resize 150 then the image grows and it should not.  If you use resize 150> the image does not size because 100 is less then 150.    

If you meant to keep the the size as is and just zoom some place or crop.  Look at the third line
I ended up using for the thumbs.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thank you for the points!