Applies EXIF orientation metadata to pixel data and removes the EXIF rotation

@access protected
498160
protected function autoOrient()
    {
        // apply EXIF orientation to pixel data
        switch ($this->originalImage->getImageOrientation()) {
            case \Imagick::ORIENTATION_BOTTOMRIGHT:
                $this->originalImage->rotateimage('#000', 180); // rotate 180 degrees
                break;
            case \Imagick::ORIENTATION_RIGHTTOP:
                $this->originalImage->rotateimage('#000', 90); // rotate 90 degrees CW
                break;
            case \Imagick::ORIENTATION_LEFTBOTTOM:
                $this->originalImage->rotateimage('#000', -90); // rotate 90 degrees CCW
                break;
        }

        // reset EXIF orientation
        $this->originalImage->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
    }
328706
public function getExifInfos()
    {
        if (!$this->exists()) {
            return false;
        }
        $exifdata = array();
        if ($data = exif_read_data($this->getRealPath(), 'EXIF', true)) {
            foreach ($data as $key => $section) {
                foreach ($section as $name => $value) {
                    if (is_string($value)) {
                        if (!isset($exifdata[$name])) {
                            $exifdata[$name] = '';
                        }
                        $exifdata[$name] .= $value;
                    } elseif (is_array($value)) {
                        if (!isset($exifdata[$name])) {
                            $exifdata[$name] = array();
                        }
                        $exifdata[$name][] = $value;
                    }
                }
            }
            if (!empty($exifdata["GPSLongitude"]) && !empty($exifdata['GPSLongitudeRef'])) {
                $exifdata["GPSLongitudeTransformed"] = self::getGps($exifdata["GPSLongitude"][0], $exifdata['GPSLongitudeRef'][0]);
            }
            if (!empty($exifdata["GPSLatitude"]) && !empty($exifdata['GPSLatitudeRef'])) {
                $exifdata["GPSLatitudeTransformed"] = self::getGps($exifdata["GPSLatitude"][0], $exifdata['GPSLatitudeRef'][0]);
            }
            if (!empty($exifdata["DateTime"])) {
                $exifdata["DateTimeTransformed"] = self::getDateFromExif($exifdata["DateTime"]);
            }
            if (!empty($exifdata["DateTimeOriginal"])) {
                $exifdata["DateTimeOriginalTransformed"] = self::getDateFromExif($exifdata["DateTimeOriginal"]);
            }
        }
        return $exifdata;
    }
826406
function get_orientation() {
        if (imagesx($this->image) > imagesy($this->image)) {
            return 'landscape';
        }
        if (imagesx($this->image) < imagesy($this->image)) {
            return 'portrait';
        }
        return 'square';
    }
1157753
public function deleteImageTransformCaches()
    {
        $path = Plugin::$plugin->getSettings()->imagerSystemPath;

        try {
            FileHelper::clearDirectory(FileHelper::normalizePath($path));
        } catch (ErrorException $e) {
            Craft::error('Could not clear directory "'.$path.'" ('.$e->getMessage().')', __METHOD__);
        } catch (InvalidParamException $e) {
            Craft::error('Could not clear directory "'.$path.'" ('.$e->getMessage().')', __METHOD__);
        }
    }
21330
static function imageAdjustOrientation($path)
	{
		// read image
		$image = new \imagick();
		if ( !$image->readImage($path) )
			return FALSE;
		
		
		// read exif orientation
		$orientation = $image->getImageOrientation(); 
		$rotated = false;

		switch($orientation)
		{ 
			case \imagick::ORIENTATION_BOTTOMRIGHT: 
				$image->rotateimage("#000", 180); // rotate 180 degrees 
				$rotated = true;
			break; 

			case \imagick::ORIENTATION_RIGHTTOP: 
				$image->rotateimage("#000", 90); // rotate 90 degrees CW 
				$rotated = true;
			break; 

			case \imagick::ORIENTATION_LEFTBOTTOM: 
				$image->rotateimage("#000", -90); // rotate 90 degrees CCW 
				$rotated = true;
			break; 
		} 

		// Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image! 
		$image->setImageOrientation(\imagick::ORIENTATION_TOPLEFT); 
		
		
		if ( $rotated )
		{
			$image->setImageCompressionQuality(90);
			$image->writeImage($path); 
		}

		
		return TRUE;
	}
823862
public function correctOrientation()
    {
        try {
            $exif = exif_read_data($this->file);
        } catch (\Exception $e) {
            return $this;
        }
        if (!empty($exif['Orientation'])) {
            switch ($exif['Orientation']) {
                case 8:
                    $this->image = imagerotate($this->image, 90, 0);
                    break;
                case 3:
                    $this->image = imagerotate($this->image, 180, 0);
                    break;
                case 6:
                    $this->image = imagerotate($this->image, -90, 0);
                    break;
            }
        }
        return $this;
    }
308298
public static function iOSCheckOrientation($path)
    {
        if(!function_exists('exif_read_data'))
        {
            throw new \Exception("Error, PHP EXIF module isn't activated, this module is necessary to set correct image orientation from iOS device");
        }

        // get mime type
        $finfo  = new \finfo(FILEINFO_MIME_TYPE);
        $mime   = $finfo->file($path);

        if($mime == 'image/jpeg')
        {
            // Only support to jpeg and tiff
            $exif = exif_read_data($path);

            if(!empty($exif['Orientation']))
            {
                $image = imagecreatefromstring(file_get_contents($path));
                switch($exif['Orientation'])
                {
                    case 8:
                        $image = imagerotate($image,90,0);
                        break;
                    case 3:
                        $image = imagerotate($image,180,0);
                        break;
                    case 6:
                        $image = imagerotate($image,-90,0);
                        break;
                }
                imagejpeg($image, $path);
            }
        }
    }
88189
public function autoRotate()
	{
		if (!$this->checkPackageRequirements('exif'))
		{
			$this->setError(\Lang::txt('You need the PHP exif library installed to rotate image based on Exif Orientation value.'));
			return false;
		}

		if ($this->image_type == IMAGETYPE_JPEG)
		{
			try
			{
				$this->exif_data = exif_read_data($this->source);
			}
			catch (Exception $e)
			{
				$this->exif_data = array();
			}

			if (isset($this->exif_data['Orientation']))
			{
				switch ($this->exif_data['Orientation'])
				{
					case 2:
						$this->flip(true, false);
						break;

					case 3:
						$this->rotate(180);
						break;

					case 4:
						$this->flip(false, true);
						break;

					case 5:
						$this->rotate(270);
						$this->flip(true, false);
						break;

					case 6:
						$this->rotate(270);
						break;

					case 7:
						$this-rotate(90);
						$this->flip(true, false);
						break;

					case 8:
						$this->rotate(90);
						break;
				}
			}
		}
	}
977591
private int getRotationAngle(final ExifInterface exifInterface) {
    return JfifUtil.getAutoRotateAngleFromOrientation(
        Integer.parseInt(exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION)));
  }
487813
def post_processing(img)
      img.combine_options do |cmd|
        cmd.strip # Deletes metatags
        cmd.colorspace 'sRGB' # Change colorspace
        cmd.auto_orient # Reset rotation
        cmd.quiet # Suppress warnings
      end
    end
1033218
def clear_pictures(self):
        """"""

        blocks = [b for b in self.metadata_blocks if b.code != Picture.code]
        self.metadata_blocks = blocks
1310098
public static function reset()
    {
        self::$imageIdentify = null;
        self::$imageConvert  = null;
        self::$os            = null;
    }
766531
protected function reduceImage()
    {
        $imResampled = imagecreatetruecolor($this->width, $this->height);
        imagecopyresampled($imResampled, $this->im,
            0, 0, 0, 0,
            $this->width, $this->height,
            $this->width*$this->scale, $this->height*$this->scale
        );
        imagedestroy($this->im);
        $this->im = $imResampled;
    }
21426
final public function rotateImage(
		$angle              = 0,
		array $bgd_color    = array(0, 0, 0, 127),
		$ignore_transparent = false
	)
	{
		$this->_image_handle = imagerotate(
			$this->_image_handle,
			$angle,
			$this->_createImageColorAlpha($bgd_color),
			$ignore_transparent ? 1 : 0
		);
	}
622346
private function unsetMagicConstants(): void
  {
    unset($this->replace['__FILE__']);
    unset($this->replace['__ROUTINE__']);
    unset($this->replace['__DIR__']);
    unset($this->replace['__LINE__']);
  }
520502
protected function applyCustomSorting(): void
    {
        if ($this->get('orderSRC') != '') {
            $tmp = StringUtil::deserialize($this->get('orderSRC'));

            if (!empty($tmp) && is_array($tmp)) {
                // Remove all values
                $order = array_map(
                    function () {
                    },
                    array_flip($tmp)
                );

                // Move the matching elements to their position in $arrOrder
                foreach ($this->images as $k => $v) {
                    if (array_key_exists($v['uuid'], $order)) {
                        $order[$v['uuid']] = $v;
                        unset($this->images[$k]);
                    }
                }

                // Append the left-over images at the end
                if (!empty($this->images)) {
                    $order = array_merge($order, array_values($this->images));
                }

                // Remove empty (unreplaced) entries
                $this->images = array_values(array_filter($order));
                unset($order);
            }
        }
    }
857993
public function exif(array $fields = array()) {
        if (!function_exists('exif_read_data')) {
            return array();
        }

        return $this->_cache(__FUNCTION__, function($file) use ($fields) {
            /** @type \Transit\File $file */

            $exif = array();
            $fields = $fields + array(
                'make' => 'Make',
                'model' => 'Model',
                'exposure' => 'ExposureTime',
                'orientation' => 'Orientation',
                'fnumber' => 'FNumber',
                'date' => 'DateTime',
                'iso' => 'ISOSpeedRatings',
                'focal' => 'FocalLength',
                'latitude' => 'GPSLatitude',
                'longitude' => 'GPSLongitude'
            );

            if ($file->supportsExif()) {
                if ($data = @exif_read_data($file->path())) {
                    foreach ($fields as $key => $find) {
                        $value = '';

                        if (!empty($data[$find])) {
                            // Convert DMS (degrees, minutes, seconds) to decimals
                            if ($key === 'latitude' || $key === 'longitude'){
                                $deg = $data[$find][0];
                                $min = $data[$find][1];
                                $sec = $data[$find][2];
                                $value = $deg + ((($min * 60) + $sec) / 3600);

                            } else {
                                $value = $data[$find];
                            }
                        }

                        $exif[$key] = $value;
                    }
                }
            }

            // Return empty values for files that don't support exif
            if (!$exif) {
                $exif = array_map(function() {
                    return '';
                }, $fields);
            }

            return $exif;
        });
    }