Closed (won't fix)
Project:
ImageCache Actions
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Apr 2010 at 22:16 UTC
Updated:
11 Sep 2010 at 00:16 UTC
Jump to comment: Most recent file
I've written an imagecache action that crops based on entropy, which produces more pleasing results when cropping to a fixed aspect (for example it can help prevent cutting of people's heads when cropping a portrait to a square). Simpletests are included.
Would this fit in imagecache_actions? The code can be downloaded here:
http://github.com/dylantack/codename_cornbaby
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | imagecache_actions-smartcrop.jpg | 475.2 KB | dman |
Comments
Comment #1
grendzy commentedBTW if you're at drupalcon this week feel free to look me up :-)
Comment #2
dman commentedThis sounds like an awesome feature!
What a freaky algorithm (code looks really tidy, I won't try to understand it)
I've got to try this out.
No drupalcon for me this time. Paying jobs happening this month :-]
I'm actually interested in the idea that you can write simpletests for image manipulation. I thought hashing on a binary file would be doomed as a method of comparison in cases of different image compression or toolkit libraries. I've needed a testsuite for my imagecache_actions library for a while, but so far have been pumping out a test sheet for visual comparison instead.
Comment #3
grendzy commentedYou are right that hashing images for comparison doesn't usually work, you would need a more "fuzzy" metric for image similarity.
In this case, I was able to use hashing to compare cropped images - because there is no interpolation from scaling, and PNGs can be compressed losslessly.
I should also add I can't take credit for the algorithm, it was adapted it from http://code.google.com/p/sorl-thumbnail/
Comment #4
dman commentedWell, I've had a big big play with it.
I'm certainly getting above-average results from it, although it's not quite as magic as I wished to to be.
Running it on images that have the same proportions as the desired result does nothing, because the source just fits directly into the target size. But it does help a tiny bit if cropping a landscape into a square.
I did find that lining up a few optimizations in a row produced an acceptable zoom on the image features though! smartcrop 75%x100% then 100%x75% was pretty good.

It's certainly an improvement - most of the time.
Here's the testsheet I looked at. Made up of a disparate handful of not-very-randomly selected images I had handy. The smartcrop columns were - generally - an improvement on the default or center crop.
I like it.
Comment #5
grendzy commentedCool. Thanks for the thorough test-drive. Please let me know if there's any changes you'd like to the way the code is structured. (The "smartcrop" name can be changed, or folded into canvas actions, etc). I wrote this as a standalone module, before it occurred to me to suggest inclusion here.
Also, I just committed a small change to the git repo adding attribution for the authors of sorl-thumbnail.
Comment #6
dman commentedWell, I don't know how far out this is, but I was hoping that I could say "Smartcrop 25%x25%" and get the most interesting quarter of the picture. or 200x200 and get an interesting detail shot.
When I tried that, it didn't really happen like that, which is why I ended up doing the vertical then horizontal slices - which approximates the same result. Is it at all possible to focus on a smaller region like that? Or is it just intended to be a fullsize scale&crop that avoids cropping the important bit?
I think the code works well as a stand-alone, so I'd like to fold it in to imagecache_actions indeed. I've not yet reviewed the code at all, so I'll put it through the code style checker etc first - unless you'd like to?
All it really needs adding is a bit more descriptive help on the settings page. I'd like to know a little more about the process. You've described it a bit on this thread, but I want to capture it in the user docs.
Comment #7
grendzy commentedI hadn't considered that use case, but I like it. I usually get some time on Fridays to work on this.
Comment #8
grendzy commentedSome new changes in github:
Also, if you'd like I'd be happy to co-maintain this module moving forward. Thanks!
Comment #9
grendzy commentedping, wondering if you've had a change to review the new version?
Thanks for all the helpful feedback.
Comment #10
achtonsubscribe!
Comment #11
grendzy commentedThis issue seemed stalled so smartcrop has it's own home now:
http://drupal.org/project/smartcrop
dman, I hope there's no hard feelings - I do very much appreciate the feedback and testing you contributed!
Comment #12
dman commentedYeah, that's best.
I personally don't have quite enough need or love for it (or additional time) to maintain it under my umbrella, and it runs just fine as a stand-alone feature, so go for it. I'll stick a cross-link on my project page here though, just to support the family of actions.
:-)