-
-
Save asifkhankadiwala/5012914a596f25137dce073a0c427dfa to your computer and use it in GitHub Desktop.
Revisions
-
cowboymathu revised this gist
Sep 8, 2014 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,11 @@ This funtion correct all the images' orientation in a given path or directory. Run: php -r "require 'correctImageOrientation.php'; correctImageOrientation('test/');" or php -r "require 'correctImageOrientation.php'; correctImageOrientation('test/test1');" or php -r "require 'correctImageOrientation.php'; correctImageOrientation('test');" */ function correctImageOrientation($directory) { $scanned_directory = array_diff(scandir($directory), array('..', '.')); -
cowboymathu revised this gist
Sep 8, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php /* Correct image orientation v1.0 Author: Mathuvathanan Mounasamy -
cowboymathu revised this gist
Sep 8, 2014 . 1 changed file with 48 additions and 44 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,55 +17,59 @@ function correctImageOrientation($directory) { print_r($scanned_directory); echo "</pre>\r\n"; foreach ($scanned_directory as &$file) { if (is_dir($directory."/".$file)) { correctImageOrientation($directory."/".$file); } else { $filen = explode(".", $file); $ext = end($filen); try { $exif = @exif_read_data($directory."/".$file); $orientation = $exif['Orientation']; if (isset($orientation) && $orientation != 1){ switch ($orientation) { case 3: $deg = 180; break; case 6: $deg = 270; break; case 8: $deg = 90; break; } if ($deg) { // If png if ($ext == "png") { $img_new = imagecreatefrompng($directory."/".$file); $img_new = imagerotate($img_new, $deg, 0); // Save rotated image imagepng($img_new,$directory.$file); }else { $img_new = imagecreatefromjpeg($directory."/".$file); $img_new = imagerotate($img_new, $deg, 0); // Save rotated image imagejpeg($img_new,$directory."/".$file,80); } } echo "<pre>"; print_r("image changed: \r\n"); print_r($directory."/".$file); echo "</pre>\r\n"; } } catch (Exception $e) { echo "error:"; echo $e; echo "error"; } } } unset($file); -
cowboymathu revised this gist
Sep 8, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ function correctImageOrientation($directory) { print_r("scanned directory: \r\n"); print_r($scanned_directory); echo "</pre>\r\n"; foreach ($scanned_directory as &$file) { $filen = explode(".", $file); $ext = end($filen); -
cowboymathu renamed this gist
Sep 8, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
cowboymathu created this gist
Sep 8, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ <?php /* Correct image orientation v1..0 Author: Mathuvathanan Mounasamy Licensed under the MIT license This funtion correct all the images' orientation in a given path or directory. Run: php -r "require 'image_rotate.php'; correctImageOrientation('test/test1/');" */ function correctImageOrientation($directory) { $scanned_directory = array_diff(scandir($directory), array('..', '.')); echo "<pre>"; print_r("scanned directory: \r\n"); print_r($scanned_directory); echo "</pre>\r\n"; foreach ($scanned_directory as &$file) { $filen = explode(".", $file); $ext = end($filen); try { $exif = @exif_read_data($directory.$file); $orientation = $exif['Orientation']; if (isset($orientation) && $orientation != 1){ switch ($orientation) { case 3: $deg = 180; break; case 6: $deg = 270; break; case 8: $deg = 90; break; } if ($deg) { // If png if ($ext == "png") { $img_new = imagecreatefrompng($directory.$file); $img_new = imagerotate($img_new, $deg, 0); // Save rotated image imagepng($img_new,$directory.$file); }else { $img_new = imagecreatefromjpeg($directory.$file); $img_new = imagerotate($img_new, $deg, 0); // Save rotated image imagejpeg($img_new,$directory.$file,80); } } echo "<pre>"; print_r("image affected: \r\n"); print_r($directory.$file); echo "</pre>\r\n"; } } catch (Exception $e) { echo "error:"; echo $e; echo "error"; } } unset($file); } ?>