Cropping a file using "stream" & "convert"

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Cropping a file using "stream" & "convert"

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping a file using "stream" & "convert"

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Cropping a file using "stream" & "convert"

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping a file using "stream" & "convert"

Post by anthony »

Unless you tell it otherwise -- yes. 72dpi is the default.

Add a -density 800 to the convert command to fix.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Cropping a file using "stream" & "convert"

Post 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!
splee
Posts: 15
Joined: 2011-07-08T22:21:01-07:00
Authentication code: 8675308

Re: Cropping a file using "stream" & "convert"

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cropping a file using "stream" & "convert"

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply