Skip to content

Commit

Permalink
Merge pull request #743 from kprajapatii/master
Browse files Browse the repository at this point in the history
Rotate image when required before crop image - CHANGED
  • Loading branch information
kprajapatii authored Apr 10, 2024
2 parents cff4eea + f75420b commit 4f8bb1b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 21 additions & 1 deletion includes/class-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,30 @@ public function upload_file( $file, $args = array() ) {
}
} else {
$upload = wp_handle_upload( $file, apply_filters( 'uwp_handle_upload_overrides', array( 'test_form' => false ) ) );

if ( ! empty( $upload['error'] ) ) {
return new WP_Error( 'upload', $upload['error'] );
} else {
if ( ! empty( $upload['type'] ) && $upload['type'] != 'image/png' && strpos( $upload['type'], 'image/' ) === 0 ) {
// Fetch additional metadata from EXIF/IPTC.
$exif_meta = wp_read_image_metadata( $upload['file'] );

if ( ! empty( $exif_meta ) && is_array( $exif_meta ) && ! empty( $exif_meta['orientation'] ) && 1 !== (int) $exif_meta['orientation'] ) {
$editor = wp_get_image_editor( $upload['file'] );

if ( ! empty( $editor ) && ! is_wp_error( $editor ) ) {
// Rotate the whole original image if there is EXIF data and "orientation" is not 1.
$rotated = $editor->maybe_exif_rotate();
$rotated = $rotated === true ? $editor->save( $editor->generate_filename( 'rotated' ) ) : false;

if ( ! empty( $rotated ) && ! is_wp_error( $rotated ) && ! empty( $rotated['path'] ) ) {
$upload['url'] = str_replace( basename( $upload['url'] ), basename( $rotated['path'] ), $upload['url'] );
$upload['file'] = $rotated['path'];
}
}
}
}

$uploaded_file->url = $upload['url'];
$uploaded_file->name = basename( $upload['file'] );
$uploaded_file->path = $upload['file'];
Expand All @@ -215,7 +236,6 @@ public function upload_file( $file, $args = array() ) {
}
}


return $uploaded_file;
}

Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ Yes, you can customize it with Elementor, but also with Gutenberg, Divi, Beaver

== Changelog ==

= 1.2.10 =
* Rotate image when required before crop image - CHANGED

= 1.2.9 =
* JS error breaks Country field in register form - FIXED

Expand Down

0 comments on commit 4f8bb1b

Please sign in to comment.