Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is it possible to add integration to Smart Crop the way ImageField Focus does?
I find that Smart crop does a fairly decent job on it's own, but would like to correct a few images that don't get cropped nicely with this module. Imagefield Focus doesn't work with Media module, so some hacking is required there. Since this module already works with media module, it would be great to have the smart crop integration as regular crop does a fairly poor job of cropping images automatically.
Comment | File | Size | Author |
---|---|---|---|
#5 | fp_smartcrop.patch | 5.41 KB | bleen |
#2 | fp_smart_crop.patch | 2.9 KB | bleen |
Comments
Comment #1
bleen CreditAttribution: bleen commentedI need to think through how that would work.... I guess I would need to have the image run through smartcrop on the fly and see if I cant get it to suggest a default focal point immediately as the image is uploaded. Im not familiar with the guts of smart crop so I do not know if this is even feasible, but I think that would be the ideal UX.
Any thoughts?
Comment #2
bleen CreditAttribution: bleen commentedThat was actually much more straight-forward than I thought it would be ... It would be better if the smartcrop module would break out its entropy calculations into a separate function so I didnt need to copy 80% of the image_gd_smartcrop_crop function into focal_point.
Comment #3
bleen CreditAttribution: bleen commentedBasically, this works on the initial upload of an image (and only on the initial upload). Also, I have made this configurable since smartcrop can be very slow...
Comment #4
Elijah LynnHah, needs work, call to undefined function!
Comment #5
bleen CreditAttribution: bleen commentedForgot a file in the previous patch
Comment #6
Elijah LynnWorks!
Comment #7
bleen CreditAttribution: bleen commentedhttp://drupalcode.org/project/focal_point.git/commit/b41afb6... wrong commit. But I'm on a network that blocks SSH. Will push to origin laterComment #9
GaëlGI worked on having better performance. Made many tests to get something both accurate and fast.
Many problems with the current algorithm:
* Using the smartcrop algorithm as-is is slow because in our case we try to get the most entropic point, not the most entropic area. So many loops are done.
* The calculation is done on the full-size image, which can be very large.
* The progressive cropping is done with slices of 10px. It should be proportional to the image's size.
* The vertical crop is done on an already horizontally-cropped image. In real scale and crop life, images are never cropped both ways.
* The entropy is compared between the slices to remove. It should be compared between the potentially cropped images. This problem is explained here: http://envalo.com/image-cropping-php-using-entropy-explained/
Based on this, I implemented two algorithms: one based on the linked-above post, which cut the image into 25 slices, and one which uses the former idea to crop the image progressively from edges, but with the above problems solved.
It looks like the 25-slices algorithm is better, but I post both for information and later discussion.
25-slices algorithm:
Progressive crop algorithm:
I'm interested in feedback on this. :)
Comment #10
bleen CreditAttribution: bleen commentedA few quick thoughts:
Comment #11
GaëlGAllright, I answer in the new issue: #2370865: Algorithm for a smart default focal point.