@@ -3706,17 +3706,39 @@ MagickExport Image *ScaleImage(const Image *image,const size_t columns,
3706
3706
% o exception: return any errors or warnings in this structure.
3707
3707
%
3708
3708
*/
3709
+
3710
+ static void url_encode (const char * uri ,char * encode_uri )
3711
+ {
3712
+ char
3713
+ * p ;
3714
+
3715
+ const char
3716
+ * hex = "0123456789ABCDEF" ;
3717
+
3718
+ for (p = encode_uri ; * uri != '\0' ; uri ++ )
3719
+ if ((('a' <= * uri ) && (* uri <= 'z' )) || (('A' <= * uri ) && (* uri <= 'Z' )) ||
3720
+ (('0' <= * uri ) && (* uri <= '9' )) || (strchr ("/-_.~" ,* uri ) != 0 ))
3721
+ * p ++ = (* uri );
3722
+ else
3723
+ {
3724
+ * p ++ = '%' ;
3725
+ * p ++ = hex [(* uri >> 4 ) & 0xF ];
3726
+ * p ++ = hex [* uri & 0xF ];
3727
+ }
3728
+ * p = '\0' ;
3729
+ }
3730
+
3709
3731
MagickExport Image * ThumbnailImage (const Image * image ,const size_t columns ,
3710
3732
const size_t rows ,ExceptionInfo * exception )
3711
3733
{
3712
3734
#define SampleFactor 5
3713
3735
3714
3736
char
3715
- filename [MaxTextExtent ],
3716
- value [MaxTextExtent ];
3737
+ encode_uri [3 * MagickPathExtent + 1 ] = "/0" ;
3717
3738
3718
3739
const char
3719
- * name ;
3740
+ * name ,
3741
+ * mime_type ;
3720
3742
3721
3743
Image
3722
3744
* thumbnail_image ;
@@ -3742,8 +3764,8 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
3742
3764
x_factor ,
3743
3765
y_factor ;
3744
3766
3745
- x_factor = (ssize_t ) image -> columns /columns ;
3746
- y_factor = (ssize_t ) image -> rows /rows ;
3767
+ x_factor = (ssize_t ) image -> columns /( ssize_t ) columns ;
3768
+ y_factor = (ssize_t ) image -> rows /( ssize_t ) rows ;
3747
3769
if ((x_factor > 4 ) && (y_factor > 4 ))
3748
3770
{
3749
3771
thumbnail_image = SampleImage (clone_image ,4 * columns ,4 * rows ,exception );
@@ -3755,8 +3777,8 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
3755
3777
}
3756
3778
if ((x_factor > 2 ) && (y_factor > 2 ))
3757
3779
{
3758
- thumbnail_image = ResizeImage (clone_image ,2 * columns ,2 * rows ,BoxFilter ,
3759
- 1.0 , exception );
3780
+ thumbnail_image = ResizeImage (clone_image ,2 * columns ,2 * rows ,1.0 , BoxFilter ,
3781
+ exception );
3760
3782
if (thumbnail_image != (Image * ) NULL )
3761
3783
{
3762
3784
clone_image = DestroyImage (clone_image );
@@ -3786,36 +3808,26 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
3786
3808
name = GetNextImageProfile (thumbnail_image );
3787
3809
}
3788
3810
(void ) DeleteImageProperty (thumbnail_image ,"comment" );
3789
- (void ) CopyMagickString (value ,image -> magick_filename ,MaxTextExtent );
3790
- if (strstr (image -> magick_filename ,"//" ) == (char * ) NULL )
3791
- (void ) FormatLocaleString (value ,MaxTextExtent ,"file://%s" ,
3792
- image -> magick_filename );
3793
- (void ) SetImageProperty (thumbnail_image ,"Thumb::URI" ,value );
3794
- GetPathComponent (image -> magick_filename ,TailPath ,filename );
3795
- (void ) CopyMagickString (value ,filename ,MaxTextExtent );
3796
- if (GetPathAttributes (image -> filename ,& attributes ) != MagickFalse )
3797
- {
3798
- (void ) FormatLocaleString (value ,MaxTextExtent ,"%.20g" ,(double )
3799
- attributes .st_mtime );
3800
- (void ) SetImageProperty (thumbnail_image ,"Thumb::MTime" ,value );
3801
- }
3802
- (void ) FormatLocaleString (value ,MaxTextExtent ,"%.20g" ,(double )
3803
- attributes .st_mtime );
3804
- (void ) FormatMagickSize (GetBlobSize (image ),MagickFalse ,value );
3805
- (void ) ConcatenateMagickString (value ,"B" ,MaxTextExtent );
3806
- (void ) SetImageProperty (thumbnail_image ,"Thumb::Size" ,value );
3807
- (void ) FormatLocaleString (value ,MaxTextExtent ,"image/%s" ,image -> magick );
3808
- LocaleLower (value );
3809
- (void ) SetImageProperty (thumbnail_image ,"Thumb::Mimetype" ,value );
3811
+ url_encode (image -> filename ,encode_uri );
3812
+ if (* image -> filename != '/' )
3813
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::URI" ,"./%s" ,encode_uri );
3814
+ else
3815
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::URI" ,"file://%s" ,
3816
+ encode_uri );
3817
+ if (GetPathAttributes (image -> filename ,& attributes ) != MagickFalse )
3818
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::MTime" ,"%.20g" ,(double )
3819
+ attributes .st_mtime );
3820
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::Size" ,"%.20g" ,
3821
+ (double ) GetBlobSize (image ));
3822
+ mime_type = GetImageProperty (image ,"mime:type" );
3823
+ if (mime_type != (const char * ) NULL )
3824
+ (void ) SetImageProperty (thumbnail_image ,"Thumb::Mimetype" ,mime_type );
3810
3825
(void ) SetImageProperty (thumbnail_image ,"software" ,MagickAuthoritativeURL );
3811
- (void ) FormatLocaleString (value ,MaxTextExtent ,"%.20g" ,(double )
3812
- image -> magick_columns );
3813
- (void ) SetImageProperty (thumbnail_image ,"Thumb::Image::Width" ,value );
3814
- (void ) FormatLocaleString (value ,MaxTextExtent ,"%.20g" ,(double )
3815
- image -> magick_rows );
3816
- (void ) SetImageProperty (thumbnail_image ,"Thumb::Image::Height" ,value );
3817
- (void ) FormatLocaleString (value ,MaxTextExtent ,"%.20g" ,(double )
3818
- GetImageListLength (image ));
3819
- (void ) SetImageProperty (thumbnail_image ,"Thumb::Document::Pages" ,value );
3826
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::Image::Width" ,"%.20g" ,
3827
+ (double ) image -> magick_columns );
3828
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::Image::Height" ,"%.20g" ,
3829
+ (double ) image -> magick_rows );
3830
+ (void ) FormatImageProperty (thumbnail_image ,"Thumb::Document::Pages" ,"%.20g" ,
3831
+ (double ) GetImageListLength (image ));
3820
3832
return (thumbnail_image );
3821
3833
}
0 commit comments