Created
September 19, 2012 09:37
-
-
Save philsturgeon/3748717 to your computer and use it in GitHub Desktop.
PHP Image Manipulation
This file contains hidden or 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
{ | |
"require": { | |
"illuminate/foundation": ">=1.0.0", | |
"illuminate/auth": ">=1.0.0", | |
"illuminate/database": ">=1.0.0", | |
"illuminate/view": ">=1.0.0", | |
"amazonwebservices/aws-sdk-for-php": "1.5.*", | |
"codeguy/upload": "*", | |
"sybio/image-workshop" : "*", | |
"guzzle/guzzle": "*" | |
}, | |
"autoload": { | |
"classmap": [ | |
"app/controllers", | |
"app/models" | |
] | |
}, | |
"minimum-stability": "dev" | |
} |
This file contains hidden or 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
"require": { | |
"codeguy/upload": "*", | |
"sybio/image-workshop" : "*", | |
} |
This file contains hidden or 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
$folder = BASEPATH.'/tmp/opps/'; | |
$storage = new \Upload\Storage\FileSystem($folder, true); | |
$file = new \Upload\File('image', $storage); | |
// Validate file upload | |
$file->addValidations(array( | |
// Ensure file is of type "image/png" | |
new \Upload\Validation\Mimetype('image/png'), | |
// Ensure file is no larger than 5M (use "B", "K", M", or "G") | |
new \Upload\Validation\Size('5M') | |
)); | |
// Try to upload file | |
try { | |
$file->upload(); | |
} catch (\Exception $e) { | |
var_dump($e->getMessage()); | |
exit; | |
} |
This file contains hidden or 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
$filename = $folder.$file->getNameWithExtension(); | |
$image = new PHPImageWorkshop\ImageWorkshop(array( | |
'imageFromPath' => $filename, | |
)); | |
// Resize to 600 wide maintain ratio | |
$image->resizeInPixel(600, null, true); | |
$watermark = new ImageWorkshop(array( | |
'imageFromPath' => BASEPATH.'/img/logo.png', | |
)); | |
$image->addLayerOnTop($watermark, 20, 10, 'RB'); | |
// Save over original | |
$image->save($folder, $filename); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm kinda wondering why you would use the codeguy/upload package when laravel already brings all the validations and filesystem abstractions out of the box that the codeguy/upload package features. It brings that stuff with the same level of configuration code required in your controller.