[wp-trac] [WordPress Trac] #62712: "Edit image" in Media Modal not work for PSD/SVG ( mime_type image/* )
WordPress Trac
noreply at wordpress.org
Thu Dec 19 14:48:42 UTC 2024
#62712: "Edit image" in Media Modal not work for PSD/SVG ( mime_type image/* )
-----------------------------+------------------------------
Reporter: Hrohh | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Post Thumbnails | Version: 6.7.1
Severity: minor | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by Hrohh):
@abcd95 Yes, you are right. I want try filter load_image_to_edit_path. I
have PSD file with metadata sizes with jpg, so I can "edit image" with
full sizes, which can be usefull for webpage. I dont have free time to
try, but next week I will. I can filter admnin with ugly js hack for now.
{{{#!php
<?php
add_action( 'print_media_templates',
'core_thumbnail_generator_print_media_templates');
function core_thumbnail_generator_print_media_templates() {
?>
<script>
/* maybe this is the way? :)
jQuery(document).ready(function($){
wp.media.view.Attachment.Details.TwoColumn =
wp.media.view.Attachment.Details.TwoColumn.extend({
});
});
*/
let tmpl = document.querySelector('#tmpl-attachment-details-two-
column');
if ( tmpl ) {
tmpl.innerHTML = tmpl.innerHTML.replace(
/'image' === data.type && ! data.uploading && data.sizes
&& data.can.save/g,
"'image' === data.type && ! data.uploading && data.sizes
&& data.can.save && data.editable" );
tmpl.innerHTML = tmpl.innerHTML.replace(
/'pdf' === data.subtype && data.sizes/g,
"! data.editable && data.sizes" );
}
</script>
<?php
}
add_filter( 'wp_prepare_attachment_for_js',
'core_thumbnail_generator_wp_prepare_attachment_for_js', 10, 3 );
function core_thumbnail_generator_wp_prepare_attachment_for_js( $response,
$attachment, $meta ){
// revert full size instead $attachment_url = wp_get_attachment_url(
$attachment->ID );
if ( wp_attachment_is( 'image', $attachment ) && ! empty(
$meta['sizes'] ) && ! empty( $meta['sizes']['full'] ) ) {
$attachment_url = wp_get_attachment_url( $attachment->ID );
$base_url = str_replace( wp_basename( $attachment_url ), '',
$attachment_url );
$response['sizes']['full'] = array(
'url' => $base_url . $meta['sizes']['full']['file'],
'height' => $meta['sizes']['full']['height'],
'width' => $meta['sizes']['full']['width'],
'orientation' => $meta['sizes']['full']['height'] >
$meta['sizes']['full']['width'] ? 'portrait' : 'landscape',
);
}
// maybe editor can work with other formats? how can i get these
formats via imagick?
$response['editable'] = in_array( $attachment->post_mime_type, array(
'image/jpeg',
'image/png',
'image/gif',
'image/bmp',
'image/tiff',
'image/webp',
'image/avif'
) );
return $response;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62712#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list