Convert JPEG from 72 dpi to 300 dpi

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

Post Reply
jmann
Posts: 4
Joined: Thu Jul 07, 2016 5:00 pm

Convert JPEG from 72 dpi to 300 dpi

Post by jmann »

I've used ... -out jpeg -dpi 300 -keepdocsize -keepfiledate -overwrite -no_auto_ext ... to update my test image with success, kind of. I don't see an command to use with -keepdocsize that would keep the original size. When I convert my image from 6000x4000 72dpi it becomes 25000x16667 300dpi. What am I missing?
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

Welcome to the forum, jmann.
xnview ([url=http://newsgroup.xnview.com/viewtopic.php?p=125542#p125542]JPEG to CMYK conversion issue?[/url]) wrote:-dpi is only used for pdf, if you want to resize your picture use

Code: Select all

-resize
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

If I'm not mistaken, there's more than one way to store the DPI in JPEGs.
Are you looking for a lossless way (i.e. without recompression) to set or change the DPI?
jmann
Posts: 4
Joined: Thu Jul 07, 2016 5:00 pm

Re: Convert JPEG from 72 dpi to 300 dpi

Post by jmann »

In the Windows GUI when resizing an image there are multiple options but specifically one to change the DPI and a checkbox for Resample with a select box for types (ex. Lanczos). I want to be able to do this with nConvert command line. Currently I can successfully change the DPI to 300 using:

-out jpeg -dpi 300 -keepdocsize -keepfiledate -overwrite -no_auto_ext

However the file become massive going from 6mb to 16mb. If I exclude -keepdocsize from this command line then the file becomes 1.8mb. How do I keep the actual 6mb file size. I can do this in Photoshop but that isn't a batch solution I would use.
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

NConvert defaults to a JPEG compression factor of 85.
XnView OTOH uses the settings provided in Tools » Options... » Read/Write » Write » JPEG.
The option to Use estimated original quality if possible is not available nConvert, AFAIK.

What are the specs (Q-factor, sub-sampling, metadata, etc.) of your input files?
jmann
Posts: 4
Joined: Thu Jul 07, 2016 5:00 pm

Re: Convert JPEG from 72 dpi to 300 dpi

Post by jmann »

I'm not sure what the q-factor is. Quality of the images are 100% from the camera and sub-sampling should be 2. I've adjusted the command line to:

-out jpeg -dpi 300 -subsampling 2 -overwrite -no_auto_ext

Now my test file instead of 1.84 MB is 2.28 MB which is closer to the 6.09 MB of the original file size. Meta data is attached but I'm not sure what else if anything I can adjust on the command line to keep the original file size. Going from 6.09 MB to 2.28 MB makes me believe there has to be some kind of quality loss but if I add -q 100 to the command line the file size goes up to 10 MB.
Attachments
updated-meta.png
updated-meta.png (29.36 KiB) Viewed 9824 times
original-meta.png
original-meta.png (33.86 KiB) Viewed 9824 times
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

jmann wrote:I'm not sure what the q-factor is.
I'm referring to the quality/compression factor.

I dug up a few unedited samples (6000×4000 pixels) shot with an EOS Rebel T6i.
According to JPEGsnoop, the specifications are as follows:
  • Canon.Cs1.Quality = norm
    Canon.Cs1.ImageSize = Large
    • Approx quality factor: 90
    • Chroma subsampling: 2x1 ~ 2×1,1×1,1×1 ~ 4:2:2
  • Canon.Cs1.Quality = fine
    Canon.Cs1.ImageSize = Large
    • Approx quality factor: 97
    • Chroma subsampling: 2x1 ~ 2×1,1×1,1×1 ~ 4:2:2
Which setting (“Normal”/“Fine”) do you use?
nConvert wrote:

Code: Select all

          -q value          : JPEG/FPX/WIC/PDF quality (default : 85)
          -subsampling value : Subsampling factor
              0  : 2x2,1x1,1x1
              1  : 2x1,1x1,1x1
              2  : 1x1,1x1,1x1
jmann
Posts: 4
Joined: Thu Jul 07, 2016 5:00 pm

Re: Convert JPEG from 72 dpi to 300 dpi

Post by jmann »

Okay I tried using this command ...

-out jpeg -dpi 300 -subsampling 2 -q 96 -overwrite -no_auto_ext

This gets me to just about the original file size. For the quality setting though ... what is the real difference from -q 85 as default at 2 MB to -q 96 at 6 MB. If related to an option in Photoshop when editing an image ... what would be related?
Attachments
Camera settings we use
Camera settings we use
camera-settings.jpg (35.79 KiB) Viewed 9814 times
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

jmann wrote:For the quality setting though ... what is the real difference from -q 85 as default at 2 MB to -q 96 at 6 MB.
This is typical for JPEG compression: file size increases disproportionately to image quality beyond a factor of 75 or 80, IOW file size grows exponentially as quality improves.

These are results of my test with T6IhHOUSE.JPG (13'099'210 bytes):
  •   6'223'313 bytes | -out jpeg -dpi 300 -subsampling 2 -q 85 -overwrite -no_auto_ext
  • 13'272'757 bytes | -out jpeg -dpi 300 -subsampling 2 -q 96 -overwrite -no_auto_ext
BTW: The option -subsampling 2 tells nConvert to use no chroma sub-sampling (1×1,1×1,1×1 ~ 4:4:4), resulting in a larger file size.
jmann wrote:If related to an option in Photoshop when editing an image ... what would be related?
Apparently, there's no exact match in Photoshop for Canon's “Large/Fine” (Q97 @ 2×1) compression scheme :-|
ImpulseAdventure ([url=http://www.impulseadventure.com/photo/chroma-subsampling.html]JPEG Chroma Subsampling[/url] » Photoshop Quality and subsampling) wrote:
As an aside, note that Photoshop CS2 uses different chroma subsampling levels depending on the Save JPEG Quality settings:
  • Photoshop Save As Quality 0-6 - 2x2 Chroma Subsampling
  • Photoshop Save As Quality 7-12 - 1x1 No Chroma Subsampling
  • Photoshop Save For Web Quality 0-50 - 2x2 Chroma Subsampling
  • Photoshop Save For Web Quality 51-100 - 1x1 No Chroma Subsampling
User avatar
XnTriq
Moderator & Librarian
Posts: 6336
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Convert JPEG from 72 dpi to 300 dpi

Post by XnTriq »

@Pierre: Do you have any recommendations for changing the DPI values in JPEGs as losslessly as possible?
User avatar
xnview
Author of XnView
Posts: 43326
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Convert JPEG from 72 dpi to 300 dpi

Post by xnview »

XnTriq wrote:@Pierre: Do you have any recommendations for changing the DPI values in JPEGs as losslessly as possible?
without recompressing, no
Pierre.
David.P
Posts: 14
Joined: Wed May 02, 2007 9:26 am

Re: Convert JPEG from 72 dpi to 300 dpi

Post by David.P »

Hi @all,

is it still the case that it is not possible to change ONLY the dpi value of JPG files -- without recompressing them?

I thought I had done that in all of XnView, IrfanView, FastStone ImageViewer and ExifToolGUI -- but now that I am trying it today it doesn't seem work in any of the applications.

Help regarding this would be greatly appreciated.
1x1
Posts: 6
Joined: Sat Aug 15, 2020 3:01 am

Re: Convert JPEG from 72 dpi to 300 dpi

Post by 1x1 »

DPI is about only used by printer to adapt the size of the printed result.
It is normally a useless data to display any image on computer, so you must resize the image size in pixels to really change his size when displaying it on a computer.

DPI value can be changed without any re-compression, at least I speak about JPEG.
The width/height values of the DPI are just stored as 16bits values at offset 0x0E and 0x10 of an JPEG file header.

So to obtain 300 DPI, just change the jpg file header like that :

Code: Select all

         00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 01 2C
00000010 01 2C                                     -----
         -----                                     width
         height
012C = 300 DPI (so you can for example manually change it with an hexadecimal editor)

I know they can be stored inside the EXIF too, I suggest to remove the EXIF tag about DPI to avoid collision. (the main DPI value is just above)

Edit: I admit it's little strange that Pierre say he cannot without recompression because I have found some "old" screenshot where XnView offer this option, and without resampling also. I dont know what things have change...
Post Reply