Skip to content

Commit c1e7d5a

Browse files
author
Cristy
committed
strip thumbnail URI of decorators
1 parent 2724f9d commit c1e7d5a

File tree

1 file changed

+49
-37
lines changed

1 file changed

+49
-37
lines changed

magick/resize.c

+49-37
Original file line numberDiff line numberDiff line change
@@ -3706,17 +3706,39 @@ MagickExport Image *ScaleImage(const Image *image,const size_t columns,
37063706
% o exception: return any errors or warnings in this structure.
37073707
%
37083708
*/
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+
37093731
MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
37103732
const size_t rows,ExceptionInfo *exception)
37113733
{
37123734
#define SampleFactor 5
37133735

37143736
char
3715-
filename[MaxTextExtent],
3716-
value[MaxTextExtent];
3737+
encode_uri[3*MagickPathExtent+1] = "/0";
37173738

37183739
const char
3719-
*name;
3740+
*name,
3741+
*mime_type;
37203742

37213743
Image
37223744
*thumbnail_image;
@@ -3742,8 +3764,8 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
37423764
x_factor,
37433765
y_factor;
37443766

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;
37473769
if ((x_factor > 4) && (y_factor > 4))
37483770
{
37493771
thumbnail_image=SampleImage(clone_image,4*columns,4*rows,exception);
@@ -3755,8 +3777,8 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
37553777
}
37563778
if ((x_factor > 2) && (y_factor > 2))
37573779
{
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);
37603782
if (thumbnail_image != (Image *) NULL)
37613783
{
37623784
clone_image=DestroyImage(clone_image);
@@ -3786,36 +3808,26 @@ MagickExport Image *ThumbnailImage(const Image *image,const size_t columns,
37863808
name=GetNextImageProfile(thumbnail_image);
37873809
}
37883810
(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);
38103825
(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));
38203832
return(thumbnail_image);
38213833
}

0 commit comments

Comments
 (0)