Skip to content

Instantly share code, notes, and snippets.

@asilverstein
Forked from msurguy/upload.php
Created February 28, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asilverstein/8ced3603d837d50ba16a0ff53cc338c6 to your computer and use it in GitHub Desktop.
Save asilverstein/8ced3603d837d50ba16a0ff53cc338c6 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 …
//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