Skip to content

Instantly share code, notes, and snippets.

@msurguy
Last active August 29, 2015 13:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save msurguy/9203121 to your computer and use it in GitHub Desktop.
Save msurguy/9203121 to your computer and use it in GitHub Desktop.
using jquery fileAPI plugin (https://github.com/RubaXa/jquery.fileapi/) with Intervention Image class (intervention.olivervogel.net) to upload and resize images
ini_set("memory_limit","200M");
if( !empty($_SERVER['HTTP_ORIGIN']) ){
// Enable CORS
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Range, Content-Disposition, Content-Type');
}
if( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ){
exit;
}
$file = Input::file('filedata');
$extension = 'jpg';
$directory = 'img/avatars/temp';
$filename = sha1(time().time()).".{$extension}";
$fullPath = $directory.'/'.$filename;
$uploadSuccess = Image::make($file->getRealPath())->resize(200, 200, true, true)->resizeCanvas(200, 200, 'center', false, 'ffffff')->save($fullPath,80);
if( $uploadSuccess ) {
$base64 = base64_encode(File::get($fullPath));
$jsonBody = array(
'images' =>
array(
'filename' => $filename,
'mime' => $mime,
'size' => File::size($fullPath),
'dataURL' => 'data:'. $mime .';base64,'. $base64
)
);
return Response::json($jsonBody, 200);
} else {
return Response::json('error', 400);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment