Share Pastebin
Guest
Public paste!

Minus Creative

By: a guest | Jul 20th, 2008 | Syntax: PHP | Size: 1.04 KB | Hits: 92 | Expires: Never
Copy text to clipboard
  1. /*
  2.  * A simple implementation for an 'EXIF' auto-rotate
  3.  * option in Image lib. Uses PHP's built-in EXIF
  4.  * reading capabilities. 'IFDO' is a small subset
  5.  * of the available EXIF data. It might be
  6.  * preferred to read all EXIF data instead, and
  7.  * then pass that information back to the user
  8.  * since it's already being read. Maybe they
  9.  * should be separated, and EXIF should be
  10.  * automagically called if 'EXIF' is passed
  11.  * to rotate.
  12.  *
  13.  * This is really simple and lacks basic checks, I know.
  14.  */
  15.  
  16. /*
  17.  * Read the EXIF
  18.  */
  19. $image->exif = exif_read_data($file->image_path, 'IFD0');
  20.  
  21.  
  22. /*
  23.  * Auto-rotate based on provided EXIF
  24.  */
  25. switch($image->exif['Orientation']) {
  26.        
  27.         case 1:
  28.                 break;
  29.        
  30.         case 2:
  31.                 $image->flip(5);
  32.                 break;
  33.                
  34.         case 3:
  35.                 $image->rotate(180);
  36.                 break;
  37.                
  38.         case 4:
  39.                 $image->flip(6);
  40.                 break;
  41.                
  42.         case 5:
  43.                 $image->rotate(90)->flip(6);
  44.                 break;
  45.                
  46.         case 6:
  47.                 $image->rotate(90);
  48.                 break;
  49.                
  50.         case 7:
  51.                 $image->rotate(90)->flip(5);
  52.                 break;
  53.                
  54.         case 8:
  55.                 $image->rotate(-90);
  56.                 break;
  57. }