The media module is becoming the de facto solution for media management in Drupal 7 and we should definitely have the ability to create focus/crop rectangles on images selected via the Media Browser. The attached patch offers that integration.
If you have the Media module (7.x-2.x) installed then you can open the Media Browser and do the following:
- Upon uploading, instead of just clicking "submit" you can click "Upload and Set Focus" (maybe this should be "Add to Library"?)
- From the library, select an item and the focus form appears. Making changes to this focus and crop rectangles are saved automatically.
The primary mechanism by which this integration happens is by including a new imagefield_focus.media.js file whenever the media browser is opened. It basically latches on to a couple of existing js functions, namely the item list and item render functions, and injects the logic it needs to there. In addition it adds some logic to handle adding focus to a file immediately upon uploading.
There were several places where I made the existing code a bit more generic so that it could be used (as it is now) with image fields as well as with media fields.
- These patches are intended to work with the 7.x-2.x version of the media module. (If anyone feels like making this work for Media 7.x-1.x then the patch in #3 should be a good start)
- The only change to the current behavior of this module is that I had to remove the CSS style that forces images to have a min-width of 500px. Personally I have always found this an odd behavior anyway, but it definitely breaks the default layout of the media browser to have it there.
Left to do...
It occurs to me as I write this that I never tested what happens if I select a non-image from the meda browser library. I *think* it should be handled ok, but I need to look at that. Add crop/focus form to the /file/%fid/edit page Add crop/focus form to views-based media libraries