вот то что использую я но у меня тут и рендер
use Request;
use Image;
use Response;
use File;
use Input;
class UploadController extends Controller
{
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$path = Request::input('now');
$files = Input::file('file');
$link = [];
foreach ($files as $file) {
if ($file) {
$directory = public_path() . '/zakaz/' . $path . '/temp/';
$linkpath = '/zakaz/' . $path . '/temp/';
$filename = uniqid() . str_replace(" ", "", $file->getClientOriginalName());
$upload_success = $file->move($directory, $filename);
if ($upload_success) {
$info = [$file->getClientOriginalName() => $linkpath . $filename];
$link += $info;
} else {
}
}
}
return Response::json($link);
}
public function imgSize(Request $request)
{
if (Request::ajax()) {
$data = Input::all();
$imageinfo = getimagesize(public_path() . $data['path']);
return Response::json($imageinfo);
}
}
public function changeName(Request $request)
{
if (Request::ajax()) {
$data = Input::all();
$json_url = "https://api.instagram.com/v1/users/search?q=" . $data['name'] . "&access_token=" . $data['sectoken'];
$json = file_get_contents($json_url);
$links = json_decode($json);
return Response::json($links->data[0]->id);
}
}
public function cropping(Request $request)
{
function getExtension($filename)
{
return substr($filename, strrpos($filename, '.') + 1);
}
function getFname($filename)
{
return basename($filename, "." . getExtension($filename));
}
if (Request::ajax()) {
$data = Input::all();
if (!file_exists(public_path() . '/zakaz/' . $data['now'] . '/temp/crop')) {
mkdir(public_path() . '/zakaz/' . $data['now'] . '/temp/crop', 0777, true);
}
$time = time();
$imgfp = imagecreatetruecolor(640, 640) or die("Cannot Initialize new GD image stream");
if (getExtension($data['image']) == 'jpeg' || getExtension($data['image']) == 'jpg' || getExtension($data['image']) == 'JPEG' || getExtension($data['image']) == 'JPG') {
//JPG
$crpf = imagecreatefromjpeg(public_path() . $data['image']); //crop file
$crpf = imagerotate($crpf, -$data['crop']['rotate'], 0);
imagecopyresampled($imgfp, $crpf, 0, 0, $data['crop']['x'], $data['crop']['y'], 640, 640,
$data['crop']['width'], $data['crop']['height']);
imagejpeg($imgfp, '../public/zakaz/' . $data['now'] . '/temp/crop/' . $time . '.jpg', 100);
imagedestroy($crpf);
$resp = 'http://'.$_SERVER['HTTP_HOST']."/zakaz/" . $data['now'] . "/temp/crop/" . $time . '.jpg';
} elseif (getExtension($data['image']) == 'png' || getExtension($data['image']) == 'PNG') {
//PNG
$crpf = imagecreatefrompng(public_path() . $data['image']); //crop file
$crpf = imagerotate($crpf, -$data['crop']['rotate'], 0);
imagecopyresampled($imgfp, $crpf, 0, 0, $data['crop']['x'], $data['crop']['y'], 640, 640,
$data['crop']['width'], $data['crop']['height']);
imagejpeg($imgfp, '../public/zakaz/' . $data['now'] . '/temp/crop/' . $time . '.jpg', 100);
imagedestroy($crpf);
$resp = 'http://'.$_SERVER['HTTP_HOST']."/zakaz/" . $data['now'] . "/temp/crop/" . $time . '.jpg';
} else {
$resp = "lol fuck you";
}
imagedestroy($imgfp);
return Response::json($resp);
}
}
}