Created
April 18, 2013 17:54
-
-
Save msurguy/5414812 to your computer and use it in GitHub Desktop.
Automatic image rotation from mobile Recently I had a use case when I needed to automatically rotate uploaded pictures according to the sensor data embedded in the image (think iPhone, iPad, Android phones, DSLR cameras, etc) I ended up using PHP Imageworkshop (http://phpimageworkshop.com/documentation.html) for all my image processing needs so …
This file contains 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 characters
//retrieve the image | |
$image = Input::file('image'); | |
// initialize imageworkshop layer | |
$layer = PHPImageWorkshop\ImageWorkshop::initFromPath($image['tmp_name']); | |
if (File::is('jpg', $image['tmp_name'])) | |
{ | |
$exif = exif_read_data($image['tmp_name']); | |
if(isset($exif['Orientation'])&& $exif['Orientation'] == '6'){ | |
$layer->rotate(90); | |
} | |
if(isset($exif['Orientation'])&& $exif['Orientation'] == '3'){ | |
$layer->rotate(180); | |
} | |
} | |
// 2. Where do you want to store it? | |
$dirPath = path('public').'/uploads/temp/'; | |
// 3. Give it a name | |
$filename = 'avatar.jpg'; | |
// 4. If needed, do you want to create new folders? | |
$createFolders = true; | |
// 5. The backgroundcolor. Use transparent, only for PNG (otherwise it will be white if set null) | |
$backgroundColor = null; | |
// 6. Useless for GIF, usefull for PNG and JPEG (0 to 100%) | |
$imageQuality = 95; | |
// 7. Save image | |
$layer->save($dirPath, $filename, $createFolders, $backgroundColor, $imageQuality); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly what I was looking for. Thk :)