unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

feat: allow overiding `sharp.options` #13

Closed farnabaz closed 3 years ago

farnabaz commented 3 years ago

Use rotate operation to auto-rotate image based on EXIF orientation TAG.
Docs of rotate operation: https://github.com/lovell/sharp/blob/0ee08bfe46e0b204b34151fead8139027c768375/lib/operation.js#L41

fix https://github.com/nuxt/image/issues/70

pi0 commented 3 years ago
farnabaz commented 3 years ago

We may pass useExifOrientation option to sharp constructor

The sharp constructor does not support this option

There might be a reason this option is disabled by default

I didn't find any downside of enabling this. Event docs does not mention anything about downsides of this option. https://sharp.pixelplumbing.com/api-operation

farnabaz commented 3 years ago

@pi0 I've added an option to controll metadata removal on modified images

pi0 commented 3 years ago

The sharp constructor does not support this option

What about sharp.options.useExifOrientation = true? 🤔

I didn't find any downside of enabling this. Event docs does not mention anything about downsides of this option.

Feature supported by https://github.com/lovell/sharp/pull/791 (@ncoden <3) At least seems adds additional CalculateExifRotationAndFlip call (that causes flip, rotate anyway)

There is no enough context about use-case (except one issue for specific project) also about behavior of cloud resizers (like cloudinary). I would suggest keeping it same as sharp defaults unless someone needs option of having better context that for sure we need it.

farnabaz commented 3 years ago

What about sharp.options.useExifOrientation = true? 🤔

This should work, and calling rotate with no option is the same. https://github.com/lovell/sharp/blob/master/lib/operation.js#L42
But the idea can be useful, we can support an IPX option to modify Sharp options

Object.assign(sharp.options, ipx.options)
pi0 commented 3 years ago

This should work, and calling rotate with no option is the same. https://github.com/lovell/sharp/blob/master/lib/operation.js#L42

I see. Yet i would prefer using explicit option instead of implicitly calling rotate() for exif

farnabaz commented 3 years ago

@pi0 What do you think about changes?

This is really cool because users can control default behavior of sharp. What I love most is controling default quality for different formats

farnabaz commented 3 years ago

We may notice in documentation (both ipx and image module) that changing sharp options, needs a manual cache revalidation (or automate by generating cahce/integerity file with a checksum of options and invalidate directory if mistmatched)

I suggest to add docs and we can implement automation logic later