-
Notifications
You must be signed in to change notification settings - Fork 4
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
Clip when crop is not explicitly set #11
Comments
Hi @philipmarnef But I recently ran into the same issue myself with clients not defining the clip area. clip:
defaultwidth: 200
defaultheight: 400
defaultposition: top left Where defaultposition works the same way as Kirby's crop options |
That would work. An easier solution could be to have a field method that checks whether a clip was set. That way you could crop with Kirby's native methods as a fallback. Or does this exist already (no time to dig in atm, sorry)? |
If nothing was set from the panel, what would you expect from the fieldmethod / how would you use the native crop method? |
Something like (presuming the field is not empty):
could work, no? |
Ok, that is possible. $image = $imagefield->toImage();
if ($image->getClip() !== null) {
echo $image->clip();
} else {
echo $image->crop(600, 400);
} It does not solve your initial question though.
With the current blueprint clip option there is not enough information to automatically process the fallback crop. |
I thought I had tried There is a way to get the clip field minwidth and minheight: EDIT: just tried this in a snippet for a fallback and it works: $parent = $clipfield->parent();
$fieldname = $clipfield->key();
if(is_a($parent, 'Kirby\Cms\Page') && isset($parent->blueprint()->field($fieldname)['clip'])):
$clip = $parent->blueprint()->field($fieldname)['clip'];
$minw = $clip['minwidth'];
$minh = $clip['minheight'];
$fallback = $clipfield->toFile()->crop($minw, $minh)->url()
[...] Feel free to improve, it's already late 🙂 EDIT2: the above does not work if your field is nested in a structure, so would need a different solution |
I was wondering if there are any plans on when this feature will be added to the plugin? No pressure, just out of curiosity - seems like a nice addition. |
When a file is uploaded to an image clip field and the crop is not set through the GUI, the
clip()
method doesn't clip but renders the original image instead. Is there a way to make sure images are always cropped to the ratio set in the blueprint?The text was updated successfully, but these errors were encountered: