@@ -704,7 +704,7 @@ class AVConvFileWriter(AVConvBase, FFMpegFileWriter):
704
704
'''
705
705
706
706
707
- # Base class for animated GIFs with convert utility
707
+ # Base class for animated GIFs with ImageMagick
708
708
class ImageMagickBase (object ):
709
709
'''Mixin class for ImageMagick output.
710
710
@@ -724,48 +724,33 @@ def output_args(self):
724
724
return [self .outfile ]
725
725
726
726
@classmethod
727
- def _init_from_registry (cls ):
728
- if sys .platform != 'win32' or rcParams [cls .exec_key ] != 'convert' :
729
- return
730
- import winreg
731
- for flag in (0 , winreg .KEY_WOW64_32KEY , winreg .KEY_WOW64_64KEY ):
732
- try :
733
- hkey = winreg .OpenKeyEx (winreg .HKEY_LOCAL_MACHINE ,
734
- r'Software\Imagemagick\Current' ,
735
- 0 , winreg .KEY_QUERY_VALUE | flag )
736
- binpath = winreg .QueryValueEx (hkey , 'BinPath' )[0 ]
737
- winreg .CloseKey (hkey )
738
- break
739
- except Exception :
740
- binpath = ''
741
- if binpath :
742
- for exe in ('convert.exe' , 'magick.exe' ):
743
- path = os .path .join (binpath , exe )
744
- if os .path .exists (path ):
745
- binpath = path
746
- break
747
- else :
748
- binpath = ''
749
- rcParams [cls .exec_key ] = rcParamsDefault [cls .exec_key ] = binpath
750
-
751
- @classmethod
752
- def isAvailable (cls ):
753
- '''
754
- Check to see if a ImageMagickWriter is actually available.
755
-
756
- Done by first checking the windows registry (if applicable) and then
757
- running the commandline tool.
758
- '''
759
- bin_path = cls .bin_path ()
760
- if bin_path == "convert" :
761
- cls ._init_from_registry ()
762
- return super ().isAvailable ()
763
-
764
-
765
- # Note: the base classes need to be in that order to get
766
- # isAvailable() from ImageMagickBase called and not the
767
- # one from MovieWriter. The latter is then called by the
768
- # former.
727
+ def bin_path (cls ):
728
+ binpath = super ().bin_path ()
729
+ if sys .platform == 'win32' and binpath == 'convert' :
730
+ # Check the registry to avoid confusing ImageMagick's convert with
731
+ # Windows's builtin convert.exe.
732
+ import winreg
733
+ binpath = ''
734
+ for flag in (0 , winreg .KEY_WOW64_32KEY , winreg .KEY_WOW64_64KEY ):
735
+ try :
736
+ with winreg .OpenKeyEx (
737
+ winreg .HKEY_LOCAL_MACHINE ,
738
+ r'Software\Imagemagick\Current' ,
739
+ 0 , winreg .KEY_QUERY_VALUE | flag ) as hkey :
740
+ parent = winreg .QueryValueEx (hkey , 'BinPath' )[0 ]
741
+ except OSError :
742
+ pass
743
+ if binpath :
744
+ for exe in ('convert.exe' , 'magick.exe' ):
745
+ candidate = os .path .join (parent , exe )
746
+ if os .path .exists (candidate ):
747
+ binpath = candidate
748
+ break
749
+ rcParams [cls .exec_key ] = rcParamsDefault [cls .exec_key ] = binpath
750
+ return binpath
751
+
752
+
753
+ # Combine ImageMagick options with pipe-based writing
769
754
@writers .register ('imagemagick' )
770
755
class ImageMagickWriter (ImageMagickBase , MovieWriter ):
771
756
'''Pipe-based animated gif.
@@ -782,10 +767,7 @@ def _args(self):
782
767
+ self .output_args )
783
768
784
769
785
- # Note: the base classes need to be in that order to get
786
- # isAvailable() from ImageMagickBase called and not the
787
- # one from MovieWriter. The latter is then called by the
788
- # former.
770
+ # Combine ImageMagick options with temp file-based writing
789
771
@writers .register ('imagemagick_file' )
790
772
class ImageMagickFileWriter (ImageMagickBase , FileMovieWriter ):
791
773
'''File-based animated gif writer.
0 commit comments