Changing density not working on random images
Magick.NET version
Magick.NET-Q16-HDRI-OpenMP-x64
Environment (Operating system, version and so on)
Windows 11 Pro 22H2 22621.1555
Description
I am encountering a weird bug. I am changing the density of the image to 200 but it doesn't seem to apply after I save the image.
It happens only on random images which I can't see a pattern of what could be causing it.
Steps to Reproduce
Download image from link below, https://we.tl/t-wyObfLdYYj
-
Change density of the image to 200 PPI
image.Density = new Density(200, 200, DensityUnit.PixelsPerInch); -
Save the image
image.Write($@"{path}");
Not all file formats support Density. What is your output format?
The output format is JPG.
That format should work. What is the value of path? And can you attach the image here instead?
The value of the path is just my local drive to test,
The image is too big to attach here unfortunately. But I uploaded it as well now to ImageShack.
Original: https://imagizer.imageshack.com/img922/2180/ZFWwAO.jpg
Output: https://imagizer.imageshack.com/img924/7905/YpdidB.jpg
Path: X:\processed.jpg
Turns out that your input image is not actually a .jpg file but a .webp file instead. And that format does not support changing the density of the image. It should work when you change the format to jpg (and loose quality): image.Write($@"{path}", MagickFormat.Jpg); For .webp files it would probably be better to add an ExifProfile that contains the density.
Hmm, my bad it looks like imageshack automatically converted the file to webp. The original image is JPG and have tried doing as suggested and the same thing happend. Below is the exif data of the original image.
I uploaded the original image in WeTransfer this time to avoid conversion. https://wetransfer.com/downloads/fbb938124745ad32441070ca8a04157f20230509214219/3d2c6c
ExifTool Version Number : 12.58 File Name : original.jpg Directory : X:\ File Size : 15 MB File Modification Date/Time : 2023:05:10 05:10:35+08:00 File Access Date/Time : 2023:05:11 00:58:19+08:00 File Inode Change Date/Time : 2023:05:10 05:41:29+08:00 File Permissions : -rw-r--r-- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg JFIF Version : 1.01 Current IPTC Digest : 3b05c3cb28ddf7199a52af7a3a6f8c96 Application Record Version : 2 By-line : Jackie Novak Date Created : 2016:08:20 Time Created : 19:33:40 Digital Creation Date : 2016:08:20 Digital Creation Time : 19:33:40 X Resolution : 300 Displayed Units X : inches Y Resolution : 300 Displayed Units Y : inches Global Angle : 30 Global Altitude : 30 Copyright Flag : False URL List : Slices Group Name : beach Num Slices : 1 Photoshop Thumbnail : (Binary data 2550 bytes, use -b option to extract) Has Real Merged Data : Yes Writer Name : Adobe Photoshop Reader Name : Adobe Photoshop 6.0 Photoshop Quality : 10 Photoshop Format : Progressive Progressive Scans : 3 Scans Exif Byte Order : Little-endian (Intel, II) Make : Canon Camera Model Name : Canon EOS 6D Resolution Unit : inches Software : Adobe Photoshop Lightroom 5.7.1 (Windows) Modify Date : 2016:08:20 22:11:37 Artist : Jackie Novak Exposure Time : 1/250 F Number : 4.0 Exposure Program : Manual ISO : 100 Sensitivity Type : Recommended Exposure Index Recommended Exposure Index : 100 Exif Version : 0230 Date/Time Original : 2016:08:20 19:33:40 Create Date : 2016:08:20 19:33:40 Shutter Speed Value : 1/250 Aperture Value : 4.0 Exposure Compensation : 0 Max Aperture Value : 4.0 Metering Mode : Spot Flash : Off, Did not fire Focal Length : 24.0 mm Sub Sec Time Original : 00 Sub Sec Time Digitized : 00 Color Space : sRGB Focal Plane X Resolution : 1520 Focal Plane Y Resolution : 1520 Focal Plane Resolution Unit : cm Custom Rendered : Normal Exposure Mode : Manual White Balance : Manual Scene Capture Type : Standard Serial Number : 372051000732 Lens Info : 24-105mm f/? Lens Model : EF24-105mm f/4L IS USM Lens Serial Number : 0000a2045e Compression : JPEG (old-style) Thumbnail Offset : 4484 Thumbnail Length : 11949 Profile CMM Type : Profile Version : 4.2.0 Profile Class : ColorSpace Conversion Profile Color Space Data : RGB Profile Connection Space : Lab Profile Date Time : 2007:07:25 00:05:37 Profile File Signature : acsp Primary Platform : Unknown () CMM Flags : Not Embedded, Independent Device Manufacturer : Device Model : Device Attributes : Reflective, Glossy, Positive, Color Rendering Intent : Perceptual Connection Space Illuminant : 0.9642 1 0.82491 Profile Creator : Profile ID : 34562abf994ccd066d2c5721d0d68c5d Profile Description : sRGB v4 ICC preference perceptual intent beta A To B0 : (Binary data 29712 bytes, use -b option to extract) A To B1 : (Binary data 436 bytes, use -b option to extract) B To A0 : (Binary data 29748 bytes, use -b option to extract) B To A1 : (Binary data 508 bytes, use -b option to extract) Perceptual Rendering Intent Gamut: Perceptual Reference Medium Gamut Media White Point : 0.9642 1 0.82491 Profile Copyright : Copyright 2007 International Color Consortium Chromatic Adaptation : 1.04802 0.02301 -0.05017 0.02972 0.99034 -0.01707 -0.00923 0.01028 0.75214 Image Width : 5472 Image Height : 3648 Encoding Process : Baseline DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1) Aperture : 4.0 Image Size : 5472x3648 Megapixels : 20.0 Scale Factor To 35 mm Equivalent: 1.0 Shutter Speed : 1/250 Create Date : 2016:08:20 19:33:40.00 Date/Time Original : 2016:08:20 19:33:40.00 Thumbnail Image : (Binary data 11949 bytes, use -b option to extract) Date/Time Created : 2016:08:20 19:33:40 Digital Creation Date/Time : 2016:08:20 19:33:40 Circle Of Confusion : 0.030 mm Field Of View : 73.7 deg Focal Length : 24.0 mm (35 mm equivalent: 24.0 mm) Hyperfocal Distance : 4.79 m Light Value : 12.0 Lens ID : EF24-105mm f/4L IS USM
Why do you think the density value has not changed? How are you checking this? The XResolution and YResolution in the output are from the exif thumbnail and not from the image itself.
I'm using Adobe Photoshop to verify the Density of the image as well as trying to open the output image in Magick.Net.
I am getting this output: