Post-thumbnails are rotated when uploaded via iPhone
-
I’m uploading a photo via the function below. All of the full size images show up correctly however, if I upload a photo in portrait, the post-thumbnails are rotated 90degrees. Am I doing something wrong or is this a bug? It seems as if the exif data is not read when creating thumbnails.
function add_food_photo( $formData = false, $product_id = false, $field = false ) { if ($product_id && $_FILES[$field]['size'] > 0) { require_once(ABSPATH . 'wp-admin/includes/file.php'); // Get the type of the uploaded file. This is returned as "type/extension" $check_file_type = wp_check_filetype(basename($_FILES[$field]['name'])); $uploaded_file_type = $check_file_type['type']; // Set an array containing a list of acceptable formats $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png'); // If the uploaded file is the right format if(in_array($uploaded_file_type, $allowed_file_types)) { $upload_dir = wp_upload_dir(); $file_upload_data = wp_handle_upload($_FILES[$field], array('test_form' => FALSE) ); if ( $file_upload_data ) { // delete all attachements //$attached_image = get_children( "post_parent=".$product_id."&post_type=attachment&post_mime_type=image&numberposts=1" ); $attached_image = get_children( "post_parent=".$product_id."&post_type=attachment&post_mime_type=image&numberposts=1" ); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { wp_delete_attachment($attachment_id, true); } } // print_r ($file_upload_data); exit; $image_url = $file_upload_data['file']; $image_data = file_get_contents($image_url); $filename = basename($image_url); if(wp_mkdir_p($upload_dir['path'])) $file = $upload_dir['path'] . '/' . $filename; else $file = $upload_dir['basedir'] . '/' . $filename; file_put_contents($file, $image_data); $wp_filetype = wp_check_filetype($filename, null ); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment( $attachment, $file, $product_id ); require_once(ABSPATH . 'wp-admin/includes/image.php'); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); wp_update_attachment_metadata( $attach_id, $attach_data ); set_post_thumbnail($product_id, $attach_id); // Set the feedback flag to false, since the upload was successful $upload_feedback = false; } else { // Didn't get a upload directory // wp_handle_upload returned some kind of error. $upload_feedback = 'There was an erorr uploading your image'; } } else { // Wrong file type uploaded $upload_feedback = 'Please upload only image files (jpg, gif or png).'; } } else { // No file submitted $upload_feedback = false; } return $upload_feedback; }
- The topic ‘Post-thumbnails are rotated when uploaded via iPhone’ is closed to new replies.