BKWLD / decoy

A Laravel model-based CMS
http://docs.decoy.bukwild.com/
MIT License
302 stars 44 forks source link

Allow aspect ratio to be required on image field #25

Open SomosAMambo opened 7 years ago

SomosAMambo commented 7 years ago

Hi again.

Case we set a focal point in an image and call it using crop, the image is cropped to center, losing the focal point referencial.

2 suggestions:

  1. Alter crop logic to take in consideration the focal point.
  2. (not an alternative to previous suggestion, more like an addition) add methods like resizeByWidth(<width>) and resizeByHeight(<height>) so we could keep the original aspect ratio and use focal point info and have control of image size uploaded by client. Or even a method minDimensions(<width>,<height>) which will resize the original respecting the minor dimension (width or height).
weotch commented 7 years ago

Can you send a screencap video of what you're experiencing?

Btw, the spirit of the focal point feature was to pass the selection through to CSS for use with background-size: cover. So it's kinda independent from your crop selection, which should output an image URL for a crop that has the same bounds as your choice in Decoy.

SomosAMambo commented 7 years ago

Clients could be creatures reigned by whatsoever logic, so, picture the following use case:

A client uploads a image for a marquee which has a 16/9 ratio and 1600x900 pixels on desktop. But the uploaded image has 3800x4200px. The client sets the focal point. In the template we have a ->crop(1600x900)->bkgd. The returned image is cropped to the center of the original, losing the focal point reference (which is percentual to original image scale).

That's why we suggested methods that maintain the original ratio but resizes the image for bandwidth saving, etc.

We noticed that we can force aspect ratio in the image field... this kinda solves the "issue"...

weotch commented 7 years ago

Yeahhhhh, I see what you mean.

It's almost like two different types of coordinates:

  1. An x,y to center the crop around when cropped to an aspect ratio that is different than the source aspect ratio
  2. An x,y to passthrough to CSS to inform the background-position when using cover (which is the current implementation).

You are right that the forcing the aspect ratio kinda solves this, however, currently you can't force the user to use the crop tool and set an aspect ratio.

A way I would like to sovle for your use case is, when an aspect ratio is defined for image, automatically create a cropping bounds at the aspect ratio and don't allow the user to clear it. So if you specify an aspect, it is always applied as a crop. And it defaults to the center for the image.

Does that make sense? Thoughts?

SomosAMambo commented 7 years ago

Totally.

I was experimenting with this idea. The only problem I've found is that when resizing/moving the crop boundaries, the focal point could be left outside of it.