Page 1 of 1
Cropping a file using "stream" & "convert"
Posted: 2011-07-13T02:21:02-07:00
by splee
I want to crop large jpg file (800dpi, 29288x14172pix => i.e 36.6"x17.7" ), to size 2800x14172pix (i.e 3.5"x17.7"). What I did was:
Firstly, use "stream" to avoid reading the entire image in order to reduce processing time:
"stream -map i -storage-type char -extract 2800x14172+8000+0 54_800dpi.jpg 54_1.dat"
Then, use "convert" to convert the *.dat file to JPEG image:
"convert -depth 8 -size 2800x14172 gray:54_1.dat 54_1.jpg"
But when I check the final output file 54_1.jpg, the physical dimension and dpi has changed, although the number of pixels is correct:
72dpi, 2800x14172pix, 38.9"x196.8"
How could this have happened? I was expecting the dpi to remain as 800dpi, 2800x14172pix, 3.5"x17.7"
Anyone can help?
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T17:37:18-07:00
by anthony
The dat file is RAW image data. No data type information, no meta-data, not even the size of the image. Just raw data.
In the convert you have specifed the size, and type (depth) of the data. You have addumes the numbers are in RGB order. But you have not specified the density, or any other image meta-data that may have been present in the original image.
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T17:59:10-07:00
by splee
anthony wrote:The dat file is RAW image data. No data type information, no meta-data, not even the size of the image. Just raw data.
In the convert you have specifed the size, and type (depth) of the data. You have addumes the numbers are in RGB order. But you have not specified the density, or any other image meta-data that may have been present in the original image.
Does it mean ImageMagick will automatically convert it to default 72x72dpi?
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T18:03:44-07:00
by anthony
Unless you tell it otherwise -- yes. 72dpi is the default.
Add a -density 800 to the convert command to fix.
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T18:18:24-07:00
by splee
anthony wrote:Unless you tell it otherwise -- yes. 72dpi is the default.
Add a -density 800 to the convert command to fix.
Thanks anthony it works now!
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T18:36:59-07:00
by splee
splee wrote:I want to crop large jpg file (800dpi, 29288x14172pix => i.e 36.6"x17.7" ), to size 2800x14172pix (i.e 3.5"x17.7"). What I did was:
Firstly, use "stream" to avoid reading the entire image in order to reduce processing time:
"stream -map i -storage-type char -extract 2800x14172+8000+0 54_800dpi.jpg 54_1.dat"
Then, use "convert" to convert the *.dat file to JPEG image:
"convert -depth 8 -size 2800x14172 gray:54_1.dat 54_1.jpg"
But when I check the final output file 54_1.jpg, the physical dimension and dpi has changed, although the number of pixels is correct:
72dpi, 2800x14172pix, 38.9"x196.8"
How could this have happened? I was expecting the dpi to remain as 800dpi, 2800x14172pix, 3.5"x17.7"
Anyone can help?
What happen if I want to do this:
- After the first step, convert the .dat file to a jpg file of 600dpi, and has the same physical dimension as the extracted portion of the original file? i.e the new output file should be 3.5"x17.7", 600dpi (less pixels, of course)
What command should I use?
Re: Cropping a file using "stream" & "convert"
Posted: 2011-07-13T18:41:02-07:00
by anthony
set the images current density then use -resample to resize the image to fit a new density.
http://www.imagemagick.org/Usage/resize/#resample