...still trying to convert an eps to a jpg.
I'm using ImageMagick-6.7.3-4 and Ghostscript 9.0.4.
My eps has an image embedded with the size 551x712 at 304dpi.
With
convert "test2.eps" "test2.jpg"
the resulting jpg is an image with size 553x714, including the original 551x712 from the eps and an extra border of 2 pixel top and left.
After debugging a while I found the place where this happens: in the file 'coders\ps.c'
The eps has two size definitions
%%BoundingBox: 0 0 131 169
%%HiResBoundingBox: 0 0 130.5 168.6316
The method 'ReadPSImage' has a loop which read these definitions.
First, 'BoundingBox' will be read with
Code: Select all
if (LocaleNCompare(BoundingBox,command,strlen(BoundingBox)) == 0)
count=(ssize_t) sscanf(command,BoundingBox " %lf %lf %lf %lf",&bounds.x1,
&bounds.y1,&bounds.x2,&bounds.y2);
bounds.x1 = 0
bounds.y1 = 0
bounds.x2 = 131
bounds.y2 = 169
At Line 670, bounds will be saved in the variable 'page' and 'hires_bounds'
Code: Select all
page.width=(size_t) floor(bounds.x2-bounds.x1+0.5);
page.height=(size_t) floor(bounds.y2-bounds.y1+0.5);
hires_bounds=bounds;
page.width = 131
page.height = 169
In a next step 'HiResBoundingBox' will be read at Line 649 with
Code: Select all
if (LocaleNCompare(HiResBoundingBox,command,strlen(HiResBoundingBox)) == 0)
count=(ssize_t) sscanf(command,HiResBoundingBox " %lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
bounds.x1 = 0
bounds.y1 = 0
bounds.x2 = 130.5
bounds.y2 = 168.6316
At Line 660 'bounds' is compared to 'hires_bounds'
Code: Select all
if (((bounds.x2 > hires_bounds.x2) && (bounds.y2 > hires_bounds.y2)) ||
((hires_bounds.x2 == 0.0) && (hires_bounds.y2 == 0.0)))
At Line 735
Code: Select all
page.width=(size_t) floor((double) (page.width*image->x_resolution/delta.x)+
0.5);
page.height=(size_t) floor((double) (page.height*image->y_resolution/delta.y)+
0.5);
page.width = floor((131*304/72)+0.5) = 553
page.height = floor((169*304/72)+0.5) = 714
This is not correct!
It should be
page.width = floor((130.5*304/72)+0.5) = 551
page.height = floor((168.6316*304/72)+0.5) = 712
After that I tried following changes:
At Line 649 replaced
Code: Select all
if (LocaleNCompare(HiResBoundingBox,command,strlen(HiResBoundingBox)) == 0)
count=(ssize_t) sscanf(command,HiResBoundingBox " %lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
Code: Select all
if (LocaleNCompare(HiResBoundingBox,command,strlen(HiResBoundingBox)) == 0)
{
count=(ssize_t) sscanf(command,HiResBoundingBox " %lf %lf %lf %lf",
&bounds.x1,&bounds.y1,&bounds.x2,&bounds.y2);
if (count == 4)
{ // Reset hires_bounds
hires_bounds.x2 = 0.0;
hires_bounds.y2 = 0.0;
}
}
Code: Select all
page.width=(size_t) floor((double) (page.width*image->x_resolution/delta.x)+
0.5);
page.height=(size_t) floor((double) (page.height*image->y_resolution/delta.y)+
0.5);
Code: Select all
if (hires_bounds.x2 > 0 && hires_bounds.y2 > 0)
{
page.width=(size_t) floor((double)((hires_bounds.x2-hires_bounds.x1)*image->x_resolution/delta.x)+
0.5);
page.height=(size_t) floor((double)((hires_bounds.y2-hires_bounds.y1)*image->y_resolution/delta.y)+
0.5);
}
else
{
page.width=(size_t) floor((double) (page.width*image->x_resolution/delta.x)+
0.5);
page.height=(size_t) floor((double) (page.height*image->y_resolution/delta.y)+
0.5);
}
Alex