Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created September 19, 2012 09:37
Show Gist options
  • Save philsturgeon/3748717 to your computer and use it in GitHub Desktop.
Save philsturgeon/3748717 to your computer and use it in GitHub Desktop.
PHP Image Manipulation
{
"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"
}
"require": {
"codeguy/upload": "*",
"sybio/image-workshop" : "*",
}
$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;
}
$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);
@etherealite
Copy link

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.

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