Error image rotates when cropping
-
Hello, first of all, thank you for this plugin. I’ve been looking to improve image uploads for a while, and thanks to you, it’s now easier. However, looking at my community, I noticed that some avatars appear flat. While testing, I realized that some photos come out fine, while others appear flat. Do you know why this error could be occurring? Thanks for your help.
-
Hi there,
Thank you for reaching out, and I apologize for the delayed response as we were celebrating the biggest festival season in our country.
Regarding your concern, this issue seems unusual as we haven’t received similar reports from other users so far. Could you please confirm whether the problem occurs on all devices or only on specific ones, such as mobile devices?
Once I have that information, I’ll look into it further and get back to you with an update.
Best regards,
WPMake Support Team
Subject: Solution for Rotated/Flat Avatar Images
Hi WPMake Support Team,
Thank you for your response. I’ve been investigating this issue thoroughly and found the root cause along with a complete solution.
The Problem:
The “flat” or rotated avatars occur because the plugin doesn’t read EXIF orientation metadata from images captured with mobile devices. When users take photos with their phones in portrait/landscape mode, the camera stores the orientation in EXIF data rather than physically rotating the pixels. Your plugin uploads the image as-is without correcting this orientation, causing avatars to appear sideways or upside down.
Why it’s device-specific:
- Mobile photos: Often have EXIF orientation metadata (problematic)
- Desktop/edited photos: Usually don’t have EXIF data (work fine)
- Some phones: Strip EXIF automatically (appear normal)
The Solution:
I’ve implemented a fix by adding EXIF orientation correction to the
Ajax.phpfile. Here’s the code that resolves the issue:php
/** * Fix image orientation based on EXIF data * * @param string $file_path Path to the image file * @return bool True if orientation was fixed, false otherwise */ private static function fix_image_orientation( $file_path ) { // Check if exif_read_data function exists if ( ! function_exists( 'exif_read_data' ) ) { return false; } // Read EXIF data $exif = @exif_read_data( $file_path ); if ( ! $exif || ! isset( $exif['Orientation'] ) ) { return false; } // Load the image $image = wp_get_image_editor( $file_path ); if ( is_wp_error( $image ) ) { return false; } $rotated = false; // Rotate based on EXIF orientation switch ( $exif['Orientation'] ) { case 3: $image->rotate( 180 ); $rotated = true; break; case 6: $image->rotate( -90 ); $rotated = true; break; case 8: $image->rotate( 90 ); $rotated = true; break; } if ( $rotated ) { // Save the corrected image $image->save( $file_path ); } return $rotated; }Then call this function in
method_upload()immediately after the image is uploaded:php
$uploaded = wp_handle_upload( $upload, $overrides ); remove_filter( 'upload_dir', '__return_true' ); if ( $uploaded && ! isset( $uploaded['error'] ) ) { $file_url = $uploaded['url']; $file_path = $uploaded['file']; $file_type = $uploaded['type']; // Fix image orientation based on EXIF data self::fix_image_orientation( $file_path ); $attachment_id = wp_insert_attachment( // ... rest of codeRecommendation:
I strongly suggest adding this EXIF orientation correction to the next version of your plugin. This is a common issue affecting many WordPress avatar/image upload plugins, and it would greatly improve user experience for mobile uploads.
I’ve tested this extensively with images from multiple devices and orientations, and it resolves the issue completely.
Would you consider implementing this in a future update? I’d be happy to provide more details or test any implementation you develop.
Best regards
Polaris Nexus International
Hi there,
Thank you very much for your detailed investigation and for sharing your solution. I truly appreciate the time and effort you took to identify the EXIF orientation issue and provide a working fix, your explanation and code were both excellent.
You’re absolutely right that images from mobile devices often include EXIF orientation metadata, which can cause sideways or inverted uploads when the data isn’t processed correctly.
I’m happy to let you know that we have now implemented this improvement and released the fix in the latest v1.1.2 of the plugin. The update includes automatic EXIF orientation correction for uploaded images, ensuring consistent and correct avatar display across all devices.
Thank you again for your valuable contribution, feedback like yours helps make the plugin better for everyone.
Best regards,
WPMake Support Team
The topic ‘Error image rotates when cropping’ is closed to new replies.