Skip to content

Instantly share code, notes, and snippets.

@bobmagicii
Last active October 8, 2020 00:26
Show Gist options
  • Save bobmagicii/d151a0f1a8876c63a5e7d5ccc33f4423 to your computer and use it in GitHub Desktop.
Save bobmagicii/d151a0f1a8876c63a5e7d5ccc33f4423 to your computer and use it in GitHub Desktop.
<?php
$Image = new Imagick($Filename);
$Orientation = $Image->GetImageOrientation();
<?php
$Image = new Imagick($Filename);
$Orientation = $Image->GetImageOrientation();
if($Orientation === Imagick::ORIENTATION_RIGHTTOP) {
$Image->RotateImage('#000000',-90);
}
<?php
$Image = new Imagick($Filename);
$Orientation = $Image->GetImageOrientation();
if($Orientation === Imagick::ORIENTATION_TOPRIGHT) {
$Image->FlopImage();
}
<?php
$Image = new Imagick($Filename);
$Flop = FALSE;
$Rotate = 0;
// determine the orientation of the image.
switch($Image->GetImageOrientation()) {
case Imagick::ORIENTATION_TOPLEFT:
$Rotate = 0;
break;
case Imagick::ORIENTATION_RIGHTTOP:
$Rotate = -90;
break;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$Rotate = 180;
break;
case Imagick::ORIENTATION_LEFTBOTTOM:
$Rotate = 90;
break;
case Imagick::ORIENTATION_TOPRIGHT:
$Flop = TRUE;
$Rotate = 0;
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$Flop = TRUE;
$Rotate = -90;
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
$Flop = TRUE;
$Rotate = 180;
break;
case Imagick::ORIENTATION_LEFTTOP:
$Flop = TRUE;
$Rotate = 90;
break;
}
// handle any rotation needed.
if($Rotate !== 0)
$Image->RotateImage('#000000',$Rotate);
// mirror image if needed.
if($Flop === TRUE)
$Image->FlopImage();
// then force a normal orientation and overwrite.
$Image->SetImageOrientation(Imagick::ORIENTATION_TOPLEFT);
$Image->WriteImage($Filename);
<?php
switch($Image->GetImageOrientation()) {
case Imagick::ORIENTATION_TOPRIGHT:
$Flop = TRUE;
case Imagick::ORIENTATION_TOPLEFT:
$Rotate = 0;
break;
case Imagick::ORIENTATION_RIGHTBOTTOM:
$Flop = TRUE;
case Imagick::ORIENTATION_RIGHTTOP:
$Rotate = -90;
break;
case Imagick::ORIENTATION_BOTTOMLEFT:
$Flop = TRUE;
case Imagick::ORIENTATION_BOTTOMRIGHT:
$Rotate = 180;
break;
case Imagick::ORIENTATION_LEFTTOP:
$Flop = TRUE;
case Imagick::ORIENTATION_LEFTBOTTOM:
$Rotate = 90;
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment