Jump to content
YellowLab

ImageMagick COM Problem

Recommended Posts

YellowLab

I am having a very unique, but repeatable problem with ImageMagick COM interface. Here are the applicable lines of code:

$oIM=ObjCreate("ImageMagickObject.MagickImage.1")

and then later on...

$oIM.Convert(String($arFileList[$nFileIndex])&'[0]',"-alpha", "remove",@TempDir&"\temp.jpg")

the array points to a pdf file with the "convert" command converting the first page of the pdf to a jpg with any alpha layer removed.

Every time, without fail, the first time I run the script on a freshly booted machine it crashes on the $oIM.Convert command. It does this if it isn't compiled and says there is an error executing the command on the object. If compiled, i get an error that autoit has stopped responding. Anytime I run the script, compiled or not, after this initial crash everything works perfectly fine.

I am totally at a loss as to why this is occurring and how to correct it.


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites
Danyfirex

Hello probably you're using a version that has not support pdf to jpg. I think it requires Ghostscript. You can use Ghostscript directly from commandline.

 

 

Saludos

Share this post


Link to post
Share on other sites
YellowLab

I do have GhostScript installed. The ImageMagick command works at all other times except the first time it is executed on a fresh boot.

Is there a way to convert a pdf to image with GhostScript command lines?


You can't see a rainbow without first experiencing the rain.

Share this post


Link to post
Share on other sites
Qwerty212

I did a script time ago where I needed to convert pdf files to png. I tried with ImageMagick but it failed if it wasn't installed on the computers where the script was going to work.

I finally ended using a command line program included in the xpdf called pdftopng.

pdftopng version 3.04
Copyright 1996-2014 Glyph & Cog, LLC
Usage: pdftopng [options] <PDF-file> <PNG-root>
  -f <int>          : first page to print
  -l <int>          : last page to print
  -r <int>          : resolution, in DPI (default is 150)
  -mono             : generate a monochrome PBM file
  -gray             : generate a grayscale PGM file
  -freetype <string>: enable FreeType font rasterizer: yes, no
  -aa <string>      : enable font anti-aliasing: yes, no
  -aaVector <string>: enable vector anti-aliasing: yes, no
  -opw <string>     : owner password (for encrypted files)
  -upw <string>     : user password (for encrypted files)
  -q                : don't print any messages or errors
  -cfg <string>     : configuration file to use in place of .xpdfrc
  -v                : print copyright and version info
  -h                : print usage information
  -help             : print usage information
  --help            : print usage information
  -?                : print usage information

You can also take a look at nconvert , from the same guys that did Xnview. It can do a lot of image processing from the command line without having to install anything.

If you can not directly convert from pdf to jpg with nconvert, maybe you can do a pdf to png with pdftopng and later png to jpg with nconvert.

Check the license of both programs to see if they match with any possible comercial use of your script.

If you need examples of cmd calling of both programs, just ask for it.

Greets from Barcelona

Edited by Qwerty212

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

  • Similar Content

    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      UDF:
      Test Script:
       
    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • francoiste
      By francoiste
      this is a follow-up to
      i sporadically and very rarely get an access violation exception.
      here is some simplyfied repro code:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <Array.au3> #include <security.au3> ;~ #include "ESC_Globals.au3" Global Const $WTS_CURRENT_SESSION = -1 Global Const $WTS_CURRENT_SERVER_HANDLE = 0 Global Const $WTS_CLIENTPROTOCOLTYPE = 16 Global Const $WTS_CONNECTSTATE = 8 Global Const $WTS_USERNAME = 5 Global Const $tagWTS_SESSION_INFO = _ "dword SessionId;" & _ "ptr WinStationName;" & _ "uint State" Global Const $tagWTS_PROCESS_INFO = _ "DWORD SessionId;" & _ "DWORD ProcessId;" & _ "PTR pProcessName;" & _ "PTR pUserSid" For $i = 0 To 1000 * 20 ConsoleWrite("iteration " & $i & @CRLF) _GetProcessList() Sleep(1000) Next MsgBox(0, "COMPLETED", "everything done") ;***************************************** ;# returns an array: ProcessName | ProcessID | SessionID | ProcessOwner Func _GetProcessList() Local $i, $aRet ConsoleWrite("_GetProcessList() --> " & @AutoItPID & @CRLF) Local $aProcessList = ProcessList() $aRet = DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", $WTS_CURRENT_SERVER_HANDLE, "int", 0, "int", 1, "ptr*", 0, "int*", 0) If @error Or ($aRet[0] == 0) Then MsgBox(4096 + 48, "Error", "Failed invoking WTSEnumerateProcesses") Return (SetError(1, 0, -1)) EndIf Local $array[$aRet[5]][4] Local $mem = DllStructCreate($tagWTS_PROCESS_INFO, $aRet[4]) For $i = 0 To $aRet[5] - 1 ConsoleWrite("IT: " & $i) ;# DEBUG $mem = DllStructCreate($tagWTS_PROCESS_INFO, $aRet[4] + ($i * DllStructGetSize($mem))) ConsoleWrite(" - PID: ") ;# DEBUG $array[$i][1] = Int(DllStructGetData($mem, "ProcessId"), 1) ;# convert to Int32 ConsoleWrite($array[$i][1]) ;# DEBUG ConsoleWrite("; SID: ") ;# DEBUG $array[$i][2] = Int(DllStructGetData($mem, "SessionId"), 1) ;# convert to Int32 ConsoleWrite($array[$i][2]) ;# DEBUG Local $name1 = "???" For $j = 1 To $aProcessList[0][0] If $aProcessList[$j][1] == $array[$i][1] Then $name1 = $aProcessList[$j][0] ExitLoop EndIf Next ConsoleWrite("; NAME1: " & $name1) ;# DEBUG ConsoleWrite("; NAM") ;# DEBUG Local $ret2 = DllStructGetData($mem, "pProcessName") ConsoleWrite("E") ;# DEBUG Local $ret3 = DllStructCreate("char[256]", $ret2) Local $myRet = @error ConsoleWrite(": ") ;# DEBUG If $myRet == 0 Then Local $string = "" & DllStructGetData($ret3, 1) & "" ;# <==== here it sometimes CRASHES $array[$i][0] = $string ConsoleWrite($array[$i][0]) ;# DEBUG Else MsgBox(4096 + 48, "Error", "Failed for DllStructCreate: " & $myRet) ;# i never got here $array[$i][0] = "???" ConsoleWrite($array[$i][0]) ;# DEBUG EndIf ConsoleWrite("; OWNER") ;# DEBUG Local $ret3 = _Security__LookupAccountSid(DllStructGetData($mem, "pUserSid")) ConsoleWrite(": ") ;# DEBUG If IsArray($ret3) Then $array[$i][3] = "" & $ret3[1] & "/" & $ret3[0] & "" ConsoleWrite($array[$i][3]) ;# DEBUG EndIf ConsoleWrite(@CRLF) ;# DEBUG Next ConsoleWrite("endLoop." & @CRLF) ;# DEBUG DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $aRet[4]) ConsoleWrite("_GetProcessList() <-- " & @AutoItPID & @CRLF) ;# DEBUG Return $array EndFunc ;==>_GetProcessList
      first of all i'd like to understand WHY it crashes in DllStructGetData.
      and then i'd like to AVOID it, of course
      so far i have found no way to add some try-catch logic in AutoIt.
      any ideas why it would crash under very rare circumstances?
       
      my script is 32bit executed on windows 64bit OS.
      i have seen it on both, windows 7 and windows 10.
      i have seen it with both, script execution and compiled exe.
×