PHP Read EXIF Orientation & Rotate

I want to add a function to read exif data (orientation) and rotate image as required before running the resizie function:

function resize_gd($sourceFileName, $folder, $destinationFileName, $newWidth, $newHeight, $keepProportion)
	{
		$newWidth = (int)$newWidth;
		$newHeight = (int)$newHeight;
		if (!$this->gdInfo >= 1 || !$this->checkGdFileType($sourceFileName)) {
			return false;
		}
		$img = &$this->getImg($sourceFileName);
		if ($this->hasError()) {
			return false;
		}
		$srcWidth = ImageSX($img);
		$srcHeight = ImageSY($img);

		if ( $keepProportion && ($newWidth != 0 && $srcWidth<$newWidth) && ($newHeight!=0 && $srcHeight<$newHeight) ) {
			if ($sourceFileName != $folder . $destinationFileName) {
				@copy($sourceFileName, $folder . $destinationFileName);
			}
			return true;
		}
		
		if ($keepProportion == true) {
			if ($newWidth != 0 && $newHeight != 0) {
				$ratioWidth = $srcWidth/$newWidth;
				$ratioHeight = $srcHeight/$newHeight;
				if ($ratioWidth < $ratioHeight) {
					$destWidth = $srcWidth/$ratioHeight;
					$destHeight = $newHeight;
				} else {
					$destWidth = $newWidth;
					$destHeight = $srcHeight/$ratioWidth;
				}
			} else {
				if ($newWidth != 0) {
					$ratioWidth = $srcWidth/$newWidth;
					$destWidth = $newWidth;
					$destHeight = $srcHeight/$ratioWidth;
				} else if ($newHeight != 0) {
					$ratioHeight = $srcHeight/$newHeight;
					$destHeight = $newHeight;
					$destWidth = $srcWidth/$ratioHeight;
				} else {
					$destWidth = $srcWidth;
					$destHeight = $srcHeight;
				}
			}
		} else {
			$destWidth = $newWidth; 
			$destHeight = $newHeight; 
		}
		$destWidth = round($destWidth);
		$destHeight = round($destHeight);
		if ($destWidth < 1) $destWidth = 1;
		if ($destHeight < 1) $destHeight = 1;
		
		$destImage = &$this->getImageCreate($destWidth, $destHeight);

So what now? Why don’t you do it? Or at least try? I don’t see any related code for handling EXIF data

https://www.php.net/manual/en/book.exif.php

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.