Sign in to follow this  
Followers 0
SmiLe

Creating and manipulating images...

9 posts in this topic

Hi all!

I am looking for a way to manipulate Jpeg images with AutoIt scripts (at least drawing text, resizing and sharpening if possible).

IMHO the cxImage and FreeImage libraries are not very well documented for someone who has no C/C++ skills, so I started Googleing and I found a free COM wrapper for GD library. Being able to do the same as PHP scripts would be great.

I tried to write a small test script but I can't figure out how to save the created image to a .jpg file... :)

CODE
;

; Copy bgd.dll and GDLibrary.dll in @SystemDir (see http://www.codeproject.com/asp/GDLibraryWrapper.asp)

; Register GDLibrary wrapper (regsvr32.exe GDLibrary.dll)

;

$gdImage = ObjCreate("GDLibrary.gdImage")

If IsObj($gdImage) Then

$gdImage.Create(500, 500)

$gdImage.ColorAllocate(255, 255, 255)

$Blue = $gdImage.ColorAllocate(0, 0, 255)

$gdImage.Rectangle(3, 15, 390, 440, $Blue)

$TextColor = $gdImage.ColorAllocate(233, 114, 191);

$gdImage.Chars($gdImage.FontGetLarge(), 5, 5, "Hello World!", $TextColor)

;

; Now how can I save this image to a JPEG file?

;

Else

MsgBox(0, "Error", "Failed to create object!")

EndIf

Any help would be greatly appreciated. Thank you!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

quick look in oleview.exe reveals:

SaveToFile(

[in, out] BSTR* FileName,

[in, out, optional, defaultvalue(1)] SaveOptionsEnum* Options);

$gdImage.SaveToFile("c:\somewhere\test.jpg") ; ?? not tried

Edited by Will66

Share this post


Link to post
Share on other sites

$gdImage.Chars($gdImage.FontGetLarge(), 5, 5, "Hello World!", $TextColor)

;

; Now how can I save this image to a JPEG file?

;

have you tried $gdImage.jpeg("C:\test.jpg") ??


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

http://www.autoitscript.com/forum/index.ph...mp;#entry298211

CXImageAlt.dll is activex wrapper, can do resize and sharpen, not sure about how to use the create functions.

Thank you for your reply Will66. I read your topic and tried your interesting example script before posting. But I didn't find how to call other cxImage functions, for instance cxImage.DrawString(). So I was looking for an easiest library...

(Sorry for my bad English, it is not my native language)

Share this post


Link to post
Share on other sites

have you tried $gdImage.jpeg("C:\test.jpg") ??

a quick look at the sources, reveals it's SaveToFile (as Will66 said). You don't need any options. The file name extension specifies the image type. Known types: gif,png,jpg,jpeg,bmp,gd


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

@ /dev/null:

Yes I tried $gdImage.jpeg() but it doesn't work (error: The requested action with this object has failed).

@ Will66:

Well done! $gdImage.SaveToFile("c:\somewhere\test.jpg") is perfect. Thanks a lot!!!

Share this post


Link to post
Share on other sites

heres another one in the comments section:http://www.codeproject.com/asp/GDLibraryWrapper.asp?df=100&forumid=181887&select=1131470#xx1131470xx

Share this post


Link to post
Share on other sites

I have been experimenting with the GDLibrary.dll wrapper. Unfortunately the usual GD lib functions doesn't seem to work.

For example, $gdImage.CreateFromJpeg("C:\myfile.jpg") is supposed to open an existing Jpeg file... Wrong! The GDLibrary.dll syntax is: $gdImage.LoadFromFile("C:\myfile.jpg").

More annoying, there is no way to specify Jpeg quality with $gdImage.SaveToFile("C:\myfile.jpg"). I opened a 200K image, draw "Hello World!" then save it as a new Jpeg image. The resulting file size is 700K!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0