Skip to content

Instantly share code, notes, and snippets.

@keithics
Forked from sineld/laravel-upload-resize.php
Last active December 11, 2015 04:28
Show Gist options
  • Save keithics/4545044 to your computer and use it in GitHub Desktop.
Save keithics/4545044 to your computer and use it in GitHub Desktop.
<?php
// Resizer and Image Manipulation
// Based on: http://forums.laravel.com/viewtopic.php?id=2648
public function post_edit_logo($id)
{
$rules = array('logo' => 'image');
$input = Input::file('logo');
$validation = Validator::make($input, $rules);
//file not valid
if ($validation->fails()){
return $validation->errors;
}
// create random filename
$filename = Str::random(20) .'.'. File::extension(Input::file('logo.name'));
// Save logo in the database
$event = Events::where('user_id', '=', $id)->first();
$event->logo = $filename;
$event->save();
// start bundle 'resizer'
Bundle::start('resizer');
// resize image
$success = Resizer::open($input)
->resize(60 , 30 , 'auto' )
->save('public/uploads/thumbnails/'.$filename , 90 );
// move uploaded file to public/uploads
Input::upload('logo', 'public/uploads', $filename);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment