Skip to content

Instantly share code, notes, and snippets.

@purwandi
Forked from philsturgeon/composer.json
Created September 21, 2012 07:11
Show Gist options
  • Save purwandi/3760136 to your computer and use it in GitHub Desktop.
Save purwandi/3760136 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment