2

I've seen a couple strange things that Craft does when uploading images (like upsizing jpgs). The most recent, every time I upload a .png file it changes it's DPI from 72 to 96 for some unknown reason (why is this not in the documentation?) and it doesn't alert the user that it's doing so.

1) why? 2) why is this not spelled out clearly in the documentation? 3) Shouldn't Craft alert the user that it's altering your image so you don't spend hours trying to figure out what happened to your carefully planned images? 4) how can I stop this from happening?

1

1) why?

When you upload an image to Craft, the image is automatically “cleansed” using the same basic process that Craft uses to create image transforms. That happens to ensure that there are no malicious scripts hidden in the images, and it’s not something you can disable.

2) why is this not spelled out clearly in the documentation?

Good point... we should probably mention it in the Assets section of the docs, or perhaps a knowledge base article. Will look into it.

3) Shouldn't Craft alert the user that it's altering your image so you don't spend hours trying to figure out what happened to your carefully planned images?

It would get old soon, considering it happens for 99% of uploads.

4) how can I stop this from happening?

Nothing natively, but you can bypass the whole process by manually FTP'ing up the images and running the Update Asset Indexes utility so Craft picks them up.

Worth noting that you might be better/more consistent results if your server is using Imagick over GD and make sure you're running a recent version of it.

There is a setting to this for GIFs you can disable mainly because animated GIFs can contain hundreds of frames and transforming those can bring a server down. https://docs.craftcms.com/v3/config/config-settings.html#transformgifs

| improve this answer | |
  • I get the security, but why convert to 96 dpi? Is Craft doing that? Why not check the image dpi and use that? Most of our editors will never understand this is something Craft does. I forget too then ultimately refind the answer. I don't think this is user or editor friendly. A message that Craft transformed image would help with the confusion - when editing the image? Wish there was a way to bypass this feature of Craft though - it causes me a lot of extra work. Even using FTP, if you have a lot of images, using the image re-index utility takes time too. Wanting more control and transparency. – BrianMc May 14 at 0:19
  • @BrianMC: Just curious as to what's your use case here? DPI is a setting printers use for resolution, it actually has zero impact on the web. Web browsers use the pixel dimensions of your image (and CSS) to determine how big they display on screen, not DPI. However, if you have a legitimate use case, I'd love to hear it. – RitterKnight May 14 at 20:30
  • DPI does affect the image size. If I'm trying to keep page load down (the sum of all images on a page), and I'm targeting non-retina screens, I'm going to use 72dpi for that image and size my width and height of the image so it doesn't exceed display max. 96dpi is going to increase my image size even if I set it to the same width and height - my feeling is we need to be thinking about how can minimize image file size to deliver the smallest page load. So, I'm curious why is the assets tool transforming my images to 96 dpi and increasing my file size in the process? – BrianMc May 14 at 20:40
  • I think you're confusing retina images and DPI; they are not the same. DPI doesn't matter only pixel dimensions do. To oversimplify, computers store rows and columns of dots called pixels. How many of those dots make up your image resolution (1024x1024). Craft isn't adding pixels where there aren't, which would increase the file size. However, what can affect image size is the quality (compression) you choose in your transforms. Retina images are bigger because they contain more pixels but are displayed at smaller sizes, making them appear crisper.. – RitterKnight May 14 at 21:30
  • Dang it - you're right on the DPI thing... however, we are still ignoring a primary heavy handedness that Craft is imposing on images. If me as programmer or someone as editor works very hard to reduce their images, then use something like image optim to squeeze some bytes out, and I upload to assets using Craft mechanism, it is going to inflate the images through its own process. This process is not visible to the average user and likely go unnoticed. I really think there needs to be a better way to do this! Isn't there another way you can check if an image is a security risk? – BrianMc May 19 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.