Answer the question
In order to leave comments, you need to log in
How to change the name of the received image in Intervention/Image?
I save the image in Laravel using Intervention/Image
But I can't figure out how to rename the image?
You can save a picture with a title, but you need to specify the extension in the title, but I don’t know what kind of extension the picture has - jpg, png or gif
I didn’t find anything like that in the library methods
Answer the question
In order to leave comments, you need to log in
here is what I use, but I also have a render here
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);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question