Last active
August 29, 2015 13:56
-
-
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
This file contains 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
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