Jump to content
Sign in to follow this  
autoidiot

Intermittent failure converting TIF to JPG

Recommended Posts

autoidiot

Hello all,

this is my first post here. Love the board, it has helped me iron out quirks in many small and a few larger scripts over the last 2-3 years. This time I have run into something I can't get fixed though.

As part of a larger data organizer program, I need to convert TIF files into JPG files. I decided to use the GDIPlus library for that. The problem I run into is that some of the TIF files are converted without a program and other TIF files end up as JPG files with just the header information. As a proof of concept, I am only using the small program below. At first I thought it was a size restriction, because the unsuccessful conversion all where files larger (800kB+) than the successful ones (<500kB). But then downloaded two TIF images of greater than 2MB and they got converted just fine.

#include <GDIPlus.au3>
_Main()
Func _Main()
    Local $hImage, $sCLSID
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile("C:\temp\test_in.tif")
    $sCLSID = _GDIPlus_EncodersGetCLSID("TIF")
    _GDIPlus_ImageSaveToFileEx($hImage, "C:\temp\test_out1.tif", $sCLSID)
    _GDIPlus_ImageSaveToFile($hImage, "C:\temp\test_out2.jpg")
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc

If someone is willing to help, I can send two sample TIF files (one working, one not working). I'd rather not upload them, because I am not 100% sure on the confidentiality.

Edited by autoidiot

Share this post


Link to post
Share on other sites
autoidiot

Just saw that I still had the old source code of me playing around in there. Since I can't edit the original post, here's the correct one. As you can see, I try to save the image using both _GDIPlus_ImageSaveToFileEx and _GDIPlus_ImageSaveToFile. Both yield the results described above.

#include <GDIPlus.au3>
_Main()
Func _Main()
    Local $hImage, $sCLSID
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile("C:temptest_in.tif")
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    _GDIPlus_ImageSaveToFileEx($hImage, "C:temptest_out1.jpg", $sCLSID)
    _GDIPlus_ImageSaveToFile($hImage, "C:temptest_out2.jpg")
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
EndFunc

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  

×