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