I mostly bypass the saving mechanism of the plugin. Because I wanted this to work with the Regenerate Thumbnails plugin and my custom retina @2x implementation. Here is roughly how I am doing this now:
In my ‘wp_update_attachment_metadata’ filter, I intercept your AJAX request and save a ‘thumb_meta’ array in the ‘attachment_metadata’ like this:
if (!empty($_REQUEST['action']) && $_REQUEST['action'] === 'cptSaveThumbnail' && defined('DOING_AJAX')){
$targetImg = json_decode(stripcslashes($_REQUEST['active_values']));
$singleImg = count($targetImgData) === 1;//else it's a selection
$selection = json_decode(stripcslashes($_REQUEST['selection']));
$same_ratio = !empty($_REQUEST['same_ratio']);//TODO
$ratio = number_format($targetImg[0]->ratio, 2, '.', '');
$x = (int)$selection->x;
$y = (int)$selection->y;
$x2 = (int)$selection->x2;
$y2 = (int)$selection->y2;
//custom 'thumb_meta' meta field with array of ratio sizes or names
//Note that I use X and Y just for more perf/more-compact data
$thumb_data = array('x' => $x, 'y' => $y, 'X' => $x2, 'Y' => $y2);
if (!$same_ratio && $singleImg) //individual crop, go by name
$data['thumb_meta'][$targetImg[0]->width.'x'.$targetImg[0]->height] = $thumb_data;
else
$data['thumb_meta'][$ratio] = $thumb_data;
}
Then for each ‘wp_generate_attachment_metadata’ wp core filter, I re-inject $data[‘thumb_meta’] from the saved wp_get_attachment_metadata. It’s necessaary because technically the attachment metadata is always completely regenerated, and only keeps the saved _wp_attachment_metadata[‘image_meta’] one as part of the initial base for attachment_metadata filters.
And finally I use the ‘image_resize_dimensions’ filter for the cropping with something along the lines of:
$meta_ratio = number_format($dest_w/($dest_h?$dest_h:1), 2, '.', '');
//match a ratio target with special crop-thumbnail
if (!empty($data['thumb_meta'][$meta_ratio])){
$selection = $data['thumb_meta'][$meta_ratio];
$src_w = $selection['X'] - $selection['x'];
$src_h = $selection['Y'] - $selection['y'];
$src_x = $selection['x'];
$src_y = $selection['y'];
//override wp's cropping
return array(0, 0, (int)$src_x, (int)$src_y, (int)$dst_w, (int)$dst_h, (int)$src_w, (int)$src_h);
}
I think that the most ideal way to go… Eventually you could save the cropping data as a separate post-meta to make it easier. I initially felt it was better off injected in the same metadata. Admittedly, it’s a bit of a headache.
Let me know how you’d like to do it. So I can port my cropping data to the new meta field model you choose. Or change it right now to match your storage method. I haven’t used it that much yet. But I am about to heavily use it and I critically need the crop data saved for image regeneration use, for a current project.