Skip to content

Instantly share code, notes, and snippets.

@msurguy
Created April 18, 2013 17:54
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save msurguy/5414812 to your computer and use it in GitHub Desktop.
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 …
//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);
@atomrc
Copy link

atomrc commented Oct 15, 2014

Exactly what I was looking for. Thk :)

@setkyar
Copy link

setkyar commented Mar 9, 2016

As for me I use intervention image

@llorcasantana
Copy link

Amazing bro!! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment