This project has moved. For the latest updates, please go here.

DPI

Jul 8, 2013 at 1:05 PM
Hi

How do I change the DPI for an existing image? I want to set it to 96.

I guess this is the Density property on the image but I've not been able to get it to work as required yet.

Thanks

Russell
Coordinator
Jul 8, 2013 at 1:18 PM
Can you provide me with a code sample and an example image?
Oct 21, 2013 at 6:05 PM
Hi Russell,

Have you been assisted with this yet, or have you figured out how to do this? This is one of the properties I have been trying to get working in Magick.NET as well.

Thanks.
Troy.
Feb 4, 2014 at 6:42 PM
I'm also having trouble with the density feature. It show the correct ResolutionX and ResolutionY when I set the image.Density, but the end image is still the same DPI as the original.

Thank You,
Andrew
Feb 27, 2014 at 12:49 PM
I am having the exact same issue. Has anyone found a resolution to this? I'm using MagickNet -x64 installed from the nuget package.

Thanks, Tim
Coordinator
Feb 27, 2014 at 1:04 PM
Can you provide me with a code sample and an example image?
Feb 27, 2014 at 1:24 PM
For the code, the line I'm using is:

testImage.Density = new MagickGeometry(72);
testImage.Write(filedestination);

As for the image, I'm not sure how to attach it to this reply. It's about 50 mg, 865x865. When I do a straight conversion from .eps to .jpg, the DPI shows 300dpi, which is fine. I'm just not sure how to change it to 72dpi when converting to .jpg.

Let me know if you need anything else. or how I could attaché my image.
Coordinator
Feb 27, 2014 at 1:41 PM
ImageMagick does not update the density in the profiles. When you view it in Windows explorer it can still be using the value in the profiles. Can you try adding testImage.Strip() before you do testImage.Write?
Feb 27, 2014 at 2:02 PM
Yep. .Strip() fixed me. Thanks. Really appreciate your time.
Coordinator
Feb 27, 2014 at 3:12 PM
Can you post your image on DropBox or a public image sharing service? Feel free to contact me through CodePlex if you don't want to share it publicly. I would like to investigate if I can update the profile in the image.
Feb 27, 2014 at 4:51 PM
https://www.dropbox.com/s/zp6124vntklj8p0/JLU_alt.eps

Let me know if you can't download it.
Feb 27, 2014 at 5:36 PM
Also, there does appear to be some images that imagemagick just will not convert to a desired dpi. For instance,

https://www.dropbox.com/s/l6aanp6n3gjzs5q/11267DVDLEF.eps

will not convert to .jpg at 72 dpi or 300 dpi. It always converts it to 96 dpi. Is this an imagemagic.net issue or does it have something to do with size, compression, etc. of the image itself. ?

Thanks.
Coordinator
Feb 27, 2014 at 9:25 PM
Edited Feb 27, 2014 at 9:26 PM
The problem with your images seems to be the 8BIM profile. When you remove this profile file explorer will show the correct value.

Your second image does not show the correct DPI because the ResolutionUnits value is undefined. You can get the required result with the following code:
using (MagickImage image = new MagickImage("11267DVDLEF.eps"))
{
  image.RemoveProfile("8BIM");
  image.Density = new MagickGeometry(72, 72);
  image.ResolutionUnits = Resolution.PixelsPerInch;
  image.Write("11267DVDLEF.jpg");
}
I am currently investigating if we can change ImageMagick to update the 8BIM profile, I will keep you updated.
Feb 28, 2014 at 12:17 PM
Thanks. That fixed me. As you can probably tell, I'm a little light with my knowledge of images. Thanks for your help.
Coordinator
Mar 1, 2014 at 11:06 AM
I just modified ImageMagick to update the 8BIM profile when an image is written. The next release of Magick.NET will include this fix. This means you no longer need to strip the 8BIM profile. I will also change the Density property to set the ResolutionUnits to PixelsPerInch if ResolutionUnits is undefined.
Mar 3, 2014 at 1:07 AM
Edited Mar 3, 2014 at 1:09 AM
Sweet. Thanks. Thanks for the effort.

I do have one final question. All of my image conversions are working very well except for one. It's fairly large, about 700mb. I do not get an error. My code acts as if the file converts, but the final file is only like 200kb. So, clearly it did not convert properly. Should I have any concerns about converting an image that size? It's possible that it could be my own machine limitations, but wanted to double check with you first. If you are able to convert this file, then I'll figure out a way. A code snippet would be nice, but not a big deal.

I'm trying to convert the 700mb file to .jpg 300dpi.

https://www.dropbox.com/s/onlsoqfv4y1z4uh/Gumball_S2_styleguide_MISC_GRAPHICS_Family_opening_Page.eps
Coordinator
Mar 3, 2014 at 1:50 PM
It seems the XMP profile in your file is very large. Under windows this generates a JPEG file that cannot be opened with the default image viewer of Windows. I will have to investigate if we can fix this problem. You could use image.RemoveProfile("XMP") to resolve this problem.