How to avoid WordPress stripping EXIF metadata when resizing images?
This issue has been fixed with a filter in WordPress 4.5. If you want to preserve the exif data when resizing use add_filter (‘image_strip_meta’, false);
This issue has been fixed with a filter in WordPress 4.5. If you want to preserve the exif data when resizing use add_filter (‘image_strip_meta’, false);
If you really want to use these classes the only way would be to extend both existing implementations Wp_Image_Editor_Imagick and Wp_Image_Editor_GD. Here’s an approach for the Wp_Image_Editor_GD: namespace WPSE98156; use Wp_Image_Editor_Gd, Wp_Error; class WatermarkImageEditor extends Wp_Image_Editor_Gd { /* * @param resource $stamp (A GD image resource) * * @return bool|WP_Error */ public function stamp_watermark( $stamp … Read more
I found a solution based on the code of this page: https://core.trac.wordpress.org/ticket/22180 All attachment files have a post status of ‘inherit’. So first you need to add “inherit” as one of the possible post status to search for. You can use the wp_link_query_args filter to do that. function my_wp_link_query_args( $query ) { if (is_admin()){ $query[‘post_status’] … Read more
added_post_meta seems like a good time to hook into a new image. Not only is the default meta already set but the function gives you the $post_id along with $meta_value which holds the attachment metadata. From there you can get all the fields and set the ones you want. add_action(‘added_post_meta’, ‘wpse_20151219_after_post_meta’, 10, 4); function wpse_20151219_after_post_meta($meta_id, … Read more
Thumbnails in WordPress can be generated by using wp_generate_attachment_metadata(), this function fires a filter after generating all the thumbnails wp_generate_attachment_metadata and the filter provides $metadata and $attachment_id to the hooked functions. You can hook your custom function to this filter. $metadata : Attachment metadata. What you need is $metadata[‘sizes’][‘<size-name>’], the <size-name> is the name of … Read more
Using birgire’s suggestions, I came up with the following solution that is working well with both the old pre-WP 4.x data and the newer posts that have been added under 5.0. // if there is a gallery block do this if (has_block(‘gallery’, $post->post_content)) { $post_blocks = parse_blocks($post->post_content); $ids = $post_blocks[0][attrs][ids]; } // if there is … Read more
I found a plugin that does this for me: Additional image sizes (zui) When you delete an image size that size will not be created for all NEW images you upload. However, images created for deleted sizes still exist on the server as well as the image attachment metadata for those sizes. This feature will … Read more
combining the two answer on this page, I found this worked. $args = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1 )); $loop = new WP_Query($args); while($loop->have_posts()) { the_post(); $args2 = array( ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_parent’ => $post->ID, ‘post_mime_type’ => ‘image’); $attachments = get_posts($args2); if($attachments) { foreach ($attachments as $img_post) { if( … Read more
You can do all of this using the User Role Editor plugin. I normally tend to avoid answering questions by linking directly to a plugin but in this case, what you need comes in this package.
WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media): Thumbnail (typically 150px × 150px) Medium (typically 300px × 300px) Large (typically 1024px × 1024px) It’s to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files- The … Read more