-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create AutoOrient image filter #11717
Comments
Yea, that's a good idea. It's Friday night here and I'm a bit tired, but I suspect there may be a way to make this one filter? Could we not just have a |
Misc thoughts... Is there much of a performance hit for reading the EXIF info every time? Is there a circumstance where users might want to flip x/y even when .Exif.Tags.Orientation is 0 or 1? |
I have a working implementation of this as a function...
...but have not been able to figure out how to access the EXIF data from a filter. tpl/images/images.go// AutoOrient returns the given image, rotating and flipping as needed per the
// EXIF orientation value if present.
func (ns *Namespace) AutoOrient(i images.ImageResource) (images.ImageResource, error) {
var filters = map[int]gift.Filter{
2: gift.FlipHorizontal(),
3: gift.Rotate180(),
4: gift.FlipVertical(),
5: gift.Transpose(),
6: gift.Rotate270(),
7: gift.Transverse(),
8: gift.Rotate90(),
}
if i.Exif() != nil {
orientation, ok := i.Exif().Tags["Orientation"].(int)
if ok && orientation >= 2 && orientation <= 8 {
return i.Filter(filters[orientation])
}
}
return i, nil
} Testing example (8 landscape orientations, 8 portrait orientations):
|
@jmooring re. filter vs method, I think I had the same "head scratcher" when implementing the Process filter, which I implemented using an interface to pass the "filter options" back to where the filters are applied: https://github.com/gohugoio/hugo/blob/master/resources/images/process.go#L26 You could e.g. create a new interface ala: type ImageFilterFromOrientationProvider interface {
AutoOrient(orientation int) gift.Filter
} And then adjust |
I deleted my last comment, that doesn't make sense (we cannot modify the filter), I suggest we do as suggested above, with that we can return |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This would allow users to fix orientation issues when
.Exif.Tags.Orientation
is one of 2, 4, 5 or 7.Ref: https://discourse.gohugo.io/t/image-processing-rotates-images/
The text was updated successfully, but these errors were encountered: