本文整理汇总了PHP中Intervention\Image\Image::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::make方法的具体用法?PHP Image::make怎么用?PHP Image::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initaliseImageFactory
/**
* @param $original
* @param $output
* @return ImageFactory
* @throws ImageGenerationException
*/
private function initaliseImageFactory($original, $output)
{
if (file_exists($original)) {
$path_parts = pathinfo($output);
if (!is_dir($path_parts['dirname'])) {
mkdir($path_parts['dirname'], 0777, true);
}
$imageFactory = ImageFactory::make($original);
return $imageFactory;
}
throw new ImageGenerationException();
}
示例2: saveImage
/**
* Save image in filesystem and db and return the image url.
*
* @param Upload $image
* @param boolean $useOriginalName
* @return Image
*/
public function saveImage(Upload $image, $useOriginalName = false)
{
$path = $this->makePath($image, $useOriginalName);
$this->imagine->make($image->getRealPath())->save($path, 80);
//save relative path in database instead of absolute so the site
//won't get messed up if user changes domains.
$relative = str_replace(public_path() . '/', '', $path);
$this->model->firstOrNew(array('local' => $relative, 'type' => 'upload'))->save();
return $this->byPath($relative);
}
示例3: resizeImage
/**
* Resize an image
*
* @param string $image
* @param integer $width
* @param integer $height
*
* @return Image
*/
public function resizeImage($image, $width, $height)
{
$image = Image::make('public/' . $image);
$image->resize($width, $height);
$image->save();
return $image;
}
示例4: image
/**
* @param $path
* @param $width
* @param $height
* @return Illuminate\Http\Response
*/
public function image($width, $height, $path)
{
$file = storage_path($path);
if (!file_exists($file)) {
dd($file);
App::abort(404);
}
return Image::make($file)->resize($width, $height);
}
示例5: makeNew
/**
* Make a new image
* @param MediaPath $path
* @param string $filename
* @param string null $thumbnail
*/
private function makeNew(MediaPath $path, $filename, $thumbnail)
{
$image = $this->image->make($path->getUrl());
foreach ($this->manager->find($thumbnail) as $manipulation => $options) {
$image = $this->imageFactory->make($manipulation)->handle($image, $options);
}
$image = $image->stream(pathinfo($path, PATHINFO_EXTENSION));
$this->writeImage($filename, $image);
}
示例6: makeNew
/**
* Make a new image
* @param string $path
* @param string $filename
* @param string null $thumbnail
*/
private function makeNew($path, $filename, $thumbnail)
{
$image = $this->image->make(public_path() . $path);
foreach ($this->manager->find($thumbnail) as $manipulation => $options) {
$image = $this->imageFactory->make($manipulation)->handle($image, $options);
}
$image = $image->encode(pathinfo($path, PATHINFO_EXTENSION));
$this->writeImage($filename, $image);
}
示例7: postUpload
public function postUpload()
{
if (Input::hasFile('upload')) {
$destinationPath = public_path() . '/assets/ckeditor/upload/';
$file = Input::file('upload');
$fileName = Str::random(4) . '.' . $file->getClientOriginalExtension();
Image::make($file->getRealPath())->save($destinationPath . 'original/' . $fileName)->grab('100', '100')->save($destinationPath . 'thumbnail/' . $fileName)->resize('280', '255', true)->save($destinationPath . 'resize/' . $fileName)->destroy();
return 'success';
}
return App::abort(403, 'Unauthorized action.');
}
示例8: redactor__upload
public function redactor__upload()
{
if (!Auth::getCurrentMember()) {
exit("Invalid Request");
}
$path = Request::get('path');
$is_image = Request::get('is_image');
if (isset($path)) {
$dir = Path::tidy(ltrim($path, '/') . '/');
if (isset($_POST['subfolder'])) {
$dir .= $_POST['subfolder'] . '/';
}
Folder::make($dir);
$file_type = strtolower($_FILES['file']['type']);
$file_info = pathinfo($_FILES['file']['name']);
// pull out the filename bits
$filename = $file_info['filename'];
$ext = $file_info['extension'];
// build filename
$file = $dir . $filename . '.' . $ext;
// check for dupes
if (File::exists($file)) {
$file = BASE_PATH . '/' . $dir . $filename . '-' . date('YmdHis') . '.' . $ext;
}
if (!Folder::isWritable($dir)) {
Log::error('Upload failed. Directory "' . $dir . '" is not writable.', 'redactor');
echo json_encode(array('error' => "Redactor: Upload directory not writable."));
die;
}
if ($is_image && ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg')) {
if (Request::get('resize', false)) {
$image = Image::make($_FILES['file']['tmp_name']);
$width = Request::get('width', null);
$height = Request::get('height', null);
$ratio = Request::get('ratio', true);
$upsize = Request::get('upsize', false);
$quality = Request::get('quality', '75');
$image->resize($width, $height, $ratio, $upsize)->save($file, $quality);
} else {
move_uploaded_file($_FILES['file']['tmp_name'], $file);
}
} else {
move_uploaded_file($_FILES['file']['tmp_name'], $file);
}
$return = array('filelink' => Path::toAsset($file));
echo stripslashes(json_encode($return));
} else {
echo json_encode(array('error' => "Redactor: Upload directory not set."));
}
}
示例9: process
/**
* Process an uploaded file and store it in a web-accessible place.
*
* @param UploadedFile $file
* @param $publishFilename
*/
public function process(UploadedFile $file, $publishFilename)
{
// Temporary filename to work with.
$fileName = uniqid() . '_' . $file->getClientOriginalName();
$file->move($this->publishDir, $fileName);
$speakerPhoto = Image::make($this->publishDir . '/' . $fileName);
if ($speakerPhoto->height > $speakerPhoto->width) {
$speakerPhoto->resize($this->size, null, true);
} else {
$speakerPhoto->resize(null, $this->size, true);
}
$speakerPhoto->crop($this->size, $this->size);
if ($speakerPhoto->save($this->publishDir . '/' . $publishFilename)) {
unlink($this->publishDir . '/' . $fileName);
}
}
示例10: save
/**
* Function that saves a new company
* @param array $data, string $logotype
* @return Orcamentos\Model\Company $company
*/
public function save($data, $logotype)
{
$data = json_decode($data);
if (!isset($data->name) || !isset($data->telephone)) {
throw new Exception("Invalid Parameters", 1);
}
$company = $this->getCompany($data);
$taxes = 6;
if (isset($data->taxes)) {
$taxes = $data->taxes;
}
if (!isset($data->responsable)) {
$data->responsable = null;
}
$company->setName($data->name);
$company->setResponsable($data->responsable);
$company->setTaxes($taxes);
if (isset($data->city)) {
$company->setCity($data->city);
}
if (isset($data->site)) {
$company->setSite($data->site);
}
if (isset($data->telephone)) {
$company->setTelephone($data->telephone);
}
if (isset($data->email)) {
$company->setEmail($data->email);
}
if (isset($logotype)) {
$originalName = $logotype->getClientOriginalName();
$components = explode('.', $originalName);
$fileName = md5(time()) . '.' . end($components);
$file = Image::make($logotype->getPathName())->grab(80);
$file->save("public/img/logotypes/" . $fileName);
$company->setLogotype($fileName);
}
try {
$this->em->persist($company);
$this->em->flush();
return $company;
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例11: save
/**
* Function that saves a new client
* @param array $data, string $logotype
* @return Orcamentos\Model\Client $client
*/
public function save($data, $logotype = null)
{
$data = json_decode($data);
if (!isset($data->name) || !isset($data->corporateName) || !isset($data->responsable) || !isset($data->email) || !isset($data->companyId)) {
throw new Exception("Parâmetros inválidos", 1);
}
$client = null;
if (isset($data->id)) {
$client = $this->em->getRepository("Orcamentos\\Model\\Client")->find($data->id);
}
if (!$client) {
$client = new ClientModel();
}
$client->setName($data->name);
$client->setCorporateName($data->corporateName);
$client->setResponsable($data->responsable);
$client->setEmail($data->email);
if (isset($data->cnpj)) {
$client->setCnpj($data->cnpj);
}
if (isset($data->telephone)) {
$client->setTelephone($data->telephone);
}
$company = $this->em->getRepository('Orcamentos\\Model\\Company')->find($data->companyId);
if (!isset($company)) {
throw new Exception("Empresa não encontrada", 1);
}
$client->setCompany($company);
if (isset($logotype)) {
$originalName = $logotype->getClientOriginalName();
$components = explode('.', $originalName);
$fileName = md5(time()) . '.' . end($components);
$file = Image::make($logotype->getPathName())->grab(80);
$file->save("public/img/logotypes/" . $fileName);
$client->setLogotype($fileName);
}
try {
$this->em->persist($client);
$this->em->flush();
return $client;
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例12: postImage
/**
* Post an image from the admin
*
* @return Json
*/
public function postImage()
{
$file = Input::file('file');
$imageDir = Config::get('wardrobe.image_dir', 'img');
$destinationPath = public_path() . "/" . $imageDir . "/";
$filename = $file->getClientOriginalName();
$resizeEnabled = Config::get('wardrobe.image_resize.enabled', false);
if ($resizeEnabled) {
$resizeWidth = Config::get('wardrobe.image_resize.width');
$resizeHeight = Config::get('wardrobe.image_resize.height');
$image = Image::make($file->getRealPath())->resize($resizeWidth, $resizeHeight, true);
$image->save($destinationPath . $filename);
} else {
$file->move($destinationPath, $filename);
}
if (File::exists($destinationPath . $filename)) {
return Response::json(array('filename' => "/{$imageDir}/" . $filename, 'filelink' => "/{$imageDir}/" . $filename));
}
return Response::json(array('error' => 'Upload failed. Please ensure your public/' . $imageDir . ' directory is writable.'));
}
示例13: resize
/**
* Resize the image
* @return boolean
*/
private function resize()
{
$filename = $this->uploadObject->getAbsoluteSrc();
$extension = $this->uploadObject->extension;
// Does the original file exist? If not return false
if (!File::exists($filename)) {
return false;
}
// Check to see our directory for caching exists, if it doesn't recursively create it
if (!File::isDirectory($this->getPath())) {
File::makeDirectory($this->getPath(), 0777, true);
}
$img = Image::make($filename);
if ($this->crop) {
$img->fit($this->width, $this->height)->save($this->getPathFilename());
} else {
$img->resize($this->width, $this->height, true, true)->resizeCanvas($this->width, $this->height, null, false, 'ffffff')->save($this->getPathFilename());
}
return true;
}
示例14: process
/**
* Process an uploaded file and store it in a web-accessible place.
*
* @param UploadedFile $file
* @param string $publishFilename
*
* @throws \Exception
*/
public function process(UploadedFile $file, $publishFilename)
{
// Temporary filename to work with.
$tempFilename = $this->generator->generate(40);
try {
$file->move($this->publishDir, $tempFilename);
$speakerPhoto = Image::make($this->publishDir . '/' . $tempFilename);
if ($speakerPhoto->height > $speakerPhoto->width) {
$speakerPhoto->resize($this->size, null, true);
} else {
$speakerPhoto->resize(null, $this->size, true);
}
$speakerPhoto->crop($this->size, $this->size);
if ($speakerPhoto->save($this->publishDir . '/' . $publishFilename)) {
unlink($this->publishDir . '/' . $tempFilename);
}
} catch (\Exception $e) {
unlink($this->publishDir . '/' . $tempFilename);
throw $e;
}
}
示例15: postImage
/**
* Post an image from the admin
*
* @return Json
*/
public function postImage()
{
$file = Input::file('file');
$imageDir = Config::get('core::wardrobe.image_dir');
$destinationPath = public_path() . "/{$imageDir}/";
$filename = $file->getClientOriginalName();
$resizeEnabled = Config::get('core::wardrobe.image_resize.enabled');
if ($resizeEnabled) {
$resizeWidth = Config::get('core::wardrobe.image_resize.width');
$resizeHeight = Config::get('core::wardrobe.image_resize.height');
$image = Image::make($file->getRealPath())->resize($resizeWidth, $resizeHeight, true);
$image->save($destinationPath . $filename);
} else {
$file->move($destinationPath, $filename);
}
if (File::exists($destinationPath . $filename)) {
// @note - Using the absolute url so it loads images when ran in sub folder
// this will make exporting less portable and may need to re-address at a later point.
return Response::json(array('filename' => url("/{$imageDir}/" . $filename)));
}
return Response::json(array('error' => 'Upload failed. Please ensure your public/img directory is writable.'));
}