mcfc4heatons Posted June 7, 2019 Share Posted June 7, 2019 (edited) Hi, I want to create a function that reads the exif orientation data of an image and rotates it as required - needs to run before before the resize function here, I'm using GD library if that is relevant: 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); Edited June 7, 2019 by mcfc4heatons Quote Link to comment Share on other sites More sharing options...
requinix Posted June 8, 2019 Share Posted June 8, 2019 Okay. And? Quote Link to comment Share on other sites More sharing options...
maxxd Posted June 8, 2019 Share Posted June 8, 2019 This seems like a good place to start. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.