Skip to content

Commit 29f4702

Browse files
authored
Merge pull request #180 from PRX/image_size_from_download
Add download media to get its size if it does not exist in drupal
2 parents f753cd6 + 1c10bcd commit 29f4702

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

wp-content/plugins/pri-migration-helper/migration/media_filters/media-global-filters.php

+29-2
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,41 @@ function pmh_add_external_media_without_import( $url, $attributes = array(), $op
615615
if (
616616
$image_sizes
617617
&&
618-
isset( $image_sizes['width'] )
618+
( isset( $image_sizes['width'] ) && $image_sizes['width'] )
619619
&&
620-
isset( $image_sizes['height'] )
620+
( isset( $image_sizes['height'] ) && $image_sizes['height'] )
621621
) {
622622

623623
// Set width and height.
624624
$attachment_metadata['width'] = $image_sizes['width'];
625625
$attachment_metadata['height'] = $image_sizes['height'];
626+
} else {
627+
// Get the attachment URL.
628+
$s_attachment_url = wp_get_attachment_url( $attachment_id );
629+
// Initialize media fix cli object.
630+
$media_fix_cli = new PMH_Worker();
631+
632+
// Get the image dimensions.
633+
$a_image_sizes = $media_fix_cli->clean_url_get_imagesize( $s_attachment_url );
634+
update_post_meta( $attachment_id, '_temp_import_image_size_from_download', $a_image_sizes );
635+
636+
// If the image dimensions are found.
637+
if ( $a_image_sizes ) {
638+
639+
list( $i_width, $i_height ) = $a_image_sizes;
640+
641+
// Update the attachment metadata.
642+
$attachment_metadata['width'] = $i_width;
643+
$attachment_metadata['height'] = $i_height;
644+
} else {
645+
// If width and height are still missing after a dowload set them with max wp size as default value.
646+
if ( ! $attachment_metadata['width'] ) {
647+
$attachment_metadata['width'] = 2560;
648+
}
649+
if ( ! $attachment_metadata['height'] ) {
650+
$attachment_metadata['height'] = 2560;
651+
}
652+
}
626653
}
627654
}
628655

0 commit comments

Comments
 (0)