Forum Replies Created

Viewing 2 replies - 16 through 17 (of 17 total)
  • Hi guys,

    I think that this could be fixed better with just naming the #comment id uniquely, easiest way is to make it uniform with the post.

    So if it is a comment on post ID 43, then you could have #comment_43 be the selector instead of comment.

    This can easily be done:

    <div id="comment_<?php Print get_the_ID ?>"

    Thread Starter Matt McFarland

    (@matt-mcfarland)

    @bcworkz thanks for your reply it was pretty helpful. I did some digging about wp_handle_upload/ It looks like it is not something you can add a filter to (technically?) but there is a way to hook into it: https://codex.www.ads-software.com/Plugin_API/Filter_Reference/wp_handle_upload_prefilter

    add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );

    So I cracked open functions.php and added this:

    add_filter('wp_handle_upload_prefilter', 'exifRotate' );
    
    function exifRotate( $file ){
    	$file = wp_handle_upload($file);
    	$file = exif($file);
    }
    
    function exif($file) {
            //This line reads the EXIF data and passes it into an array
            $exif = read_exif_data($file['file']);
    
            //We're only interested in the orientation
            $exif_orient = isset($exif['Orientation'])?$exif['Orientation']:0;
            $rotateImage = 0;
    
            //We convert the exif rotation to degrees for further use
            if (6 == $exif_orient) {
                $rotateImage = 90;
                $imageOrientation = 1;
            } elseif (3 == $exif_orient) {
                $rotateImage = 180;
                $imageOrientation = 1;
            } elseif (8 == $exif_orient) {
                $rotateImage = 270;
                $imageOrientation = 1;
            }
    
            //if the image is rotated
            if ($rotateImage) {
    
                //WordPress 3.5+ have started using Imagick, if it is available since there is a noticeable difference in quality
                //Why spoil beautiful images by rotating them with GD, if the user has Imagick
    
                if (class_exists('Imagick')) {
                    $imagick = new Imagick();
                    $imagick->readImage($file['file']);
                    $imagick->rotateImage(new ImagickPixel(), $rotateImage);
                    $imagick->setImageOrientation($imageOrientation);
                    $imagick->writeImage($file['file']);
                    $imagick->clear();
                    $imagick->destroy();
                } else {
    
                    //if no Imagick, fallback to GD
                    //GD needs negative degrees
                    $rotateImage = -$rotateImage;
    
                    switch ($file['type']) {
                        case 'image/jpeg':
                            $source = imagecreatefromjpeg($file['file']);
                            $rotate = imagerotate($source, $rotateImage, 0);
                            imagejpeg($rotate, $file['file']);
                            break;
                        case 'image/png':
                            $source = imagecreatefrompng($file['file']);
                            $rotate = imagerotate($source, $rotateImage, 0);
                            imagepng($rotate, $file['file']);
                            break;
                        case 'image/gif':
                            $source = imagecreatefromgif($file['file']);
                            $rotate = imagerotate($source, $rotateImage, 0);
                            imagegif($rotate, $file['file']);
                            break;
                        default:
                            break;
                    }
                }
            }
            // The image orientation is fixed, pass it back for further processing
            return $file;
        }

    The code above really just borrwed from rtmedia’s post that I mentioned in the first post above.

    I hope it works, I dont have an iphone to test but the website has decent traffic so should know by the end of this weekend.

Viewing 2 replies - 16 through 17 (of 17 total)