Retina Integration
-
I’ve running a function that creates retina sizes for all media on hook ‘wp_generate_attachment_metadata’
I’ve added:
function add_retina_for_cropped_thumbnails( $fullFilePath, $imageSizeName, $imageMetadata ) { $original = preg_replace( '/-\d+[Xx]\d+\./', '.', $fullFilePath ); make_it_retina( $original, $imageMetadata['width'], $imageMetadata['height'], true ); } add_action( 'crop_thumbnails_after_save_new_thumb', 'add_retina_for_cropped_thumbnails', 10, 3 );
Which works great except for the fact that the retina images don’t retain the crop, since, well, none of that crop data is being sent to my retina function.
It seems I have 2 options.
1) Write the cropping function into my retina function and then pass the crop data to it. Have to scale the cropping data to match the original source file. Is there a chance you would be able to provide a snippet of what that crop function would look like? Below I’ve pasted the metadata I’m receiving from ‘crop_thumbnails_after_save_new_thumb’.
2) Write all my add_image_size as the retina ‘@2x’ and then when I use Crop Thumbnails, I can downsize to 50%. That way the crop doesn’t matter because I could downsize on the cropped file instead of the original. If I go this way, I’d have to swap files in the database so WP doesn’t default to @2x.
Hopefully you can weigh in and provide a preferred approach.
Thanks in advance!
Metadata:
"file":"example-800x1000.jpg", "width":800, "height":1000, "mime-type":"image/jpeg", "cpt_last_cropping_data":{ "x":1025, "y":0, "x2":2275, "y2":1565, "original_width":2560, "original_height":1565 }
If I want to apply this same crop to my newly created 1600×2000 image how can I scale the crop to send to wp_crop_image
- The topic ‘Retina Integration’ is closed to new replies.