本文整理汇总了PHP中Intervention\Image\ImageManagerStatic类的典型用法代码示例。如果您正苦于以下问题:PHP ImageManagerStatic类的具体用法?PHP ImageManagerStatic怎么用?PHP ImageManagerStatic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageManagerStatic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCanvas
public function testCanvas()
{
$manager = Mockery::mock('Intervention\\Image\\ImageManager');
$managerStatic = new ImageManagerStatic($manager);
$img = $managerStatic->canvas(100, 100);
$this->assertInstanceOf('Intervention\\Image\\Image', $img);
}
示例2: testCanvas
public function testCanvas()
{
$manager = Mockery::mock('Intervention\\Image\\ImageManager');
$manager->shouldReceive('canvas')->with(100, 100, null)->once();
$managerStatic = new ImageManagerStatic($manager);
$managerStatic->canvas(100, 100);
}
示例3: setAvatarAttribute
public function setAvatarAttribute($avatar)
{
if (is_object($avatar) && $avatar->isValid()) {
ImageManagerStatic::make($avatar)->fit(150, 150)->save(public_path() . "/img/avatars/{$this->id}.jpg");
$this->attributes['avatar'] = true;
}
}
示例4: uploadBeerImg_callback
public static function uploadBeerImg_callback($request, $fileimage)
{
$image_unique_id = date('Ymdhis') . rand(0, 9999);
$beer_meta = new BeerImg();
$beer_meta->beer_id = $request['beer_id'];
$beer_meta->description = !empty($request['img_description']) ? $request['img_description'] : null;
$beer_name = !empty($request['img_description']) ? $request['img_description'] : null;
$imageName = "beerhit.com_" . strtolower($beer_name) . $request['beer_id'] . $image_unique_id . '.' . $fileimage->getClientOriginalExtension();
$path = public_path('/images/catalog/' . $imageName);
$img = ImageManagerStatic::make($fileimage);
// resize the image to a width of 960
// and constrain aspect ratio (auto width)
$img->resize(960, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$img->save($path);
//Save image information to database
$beer_meta->img_id = $image_unique_id;
$beer_meta->filename = $imageName;
$beer_meta->path = '/images/catalog/' . $imageName;
$beer_meta->user_id = \Auth::user()->id;
$beer_meta->place_id = $request['fb_place_id'];
$beer_meta->save();
\UserBeerHelper::userLog(\Auth::user()->id, $request['beer_id'], 200, $request['fb_place_id'], $image_unique_id);
}
示例5: create
/**
* @param string $name
* @param int $size
* @param string $background_color
* @param string $text_color
* @param string $font_file
* @return ImageManagerStatic
* @throws Exception
*/
public static function create($name = '', $size = 512, $background_color = '#666', $text_color = '#FFF', $font_file = '../../../font/OpenSans-Semibold.ttf')
{
if (strlen($name) <= 0) {
throw new Exception('Name must be at least 2 characters.');
}
if ($size <= 0) {
throw new Exception('Input must be greater than zero.');
}
if ($font_file === '../../../font/OpenSans-Semibold.ttf') {
$font_file = __DIR__ . "/" . $font_file;
}
if (!file_exists($font_file)) {
throw new Exception("Font file not found");
}
$str = "";
$name_ascii = strtoupper(Str::ascii($name));
$words = preg_split("/[\\s,_-]+/", $name_ascii);
if (count($words) >= 2) {
$str = $words[0][0] . $words[1][0];
} else {
$str = substr($name_ascii, 0, 2);
}
$img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function ($font) use($size, $text_color, $font_file) {
$font->file($font_file);
$font->size($size / 2);
$font->color($text_color);
$font->align('center');
$font->valign('middle');
});
return $img;
}
示例6: setFile
public function setFile($file)
{
$this->file = $file;
$this->image = Image::make($this->file);
$this->iptc = $this->image->iptc();
$this->exif = $this->image->exif();
return $this;
}
示例7: run
public function run(File $file)
{
$image = $this->intervention->make($file->getRealPath());
$image->orientate();
$image->save(null, 100);
$image->destroy();
}
示例8: run
public function run(File $file)
{
$image = $this->intervention->make($file->getRealPath());
$preserveRatio = $this->preserveRatio;
$image->resize($this->width, $this->height, function ($constraint) use($preserveRatio) {
if ($preserveRatio) {
$constraint->aspectRatio();
}
});
$image->save(null, 100);
$image->destroy();
}
示例9: f_img_resize
function f_img_resize($path, $w, $h, $watermark = null)
{
if (!$path) {
return;
}
//Image::configure(array('driver' => 'gd'));
$path_0 = $path;
if (!file_exists(WEB . $path_0)) {
return;
}
$path = str_replace('/upload/', '/upload/thum/', $path);
$new = file_dir($path);
$ext = file_ext($path);
$new = $new . '/' . file_name($path) . "_{$w_}{$h}" . '.' . $ext;
if (file_exists(WEB . $new)) {
return $new;
}
echo WEB . $path_0;
$img = Image::make(WEB . $path_0);
$img->resize($w, $h);
if (!is_dir(WEB . file_dir($new))) {
mkdir(WEB . $new, 0777, true);
}
if ($watermark) {
$img->insert(WEB . $watermark);
}
$img->save(WEB . $new);
return $new;
}
示例10: get
public function get($icon, $request, $response)
{
$info = pathinfo($icon);
$iconName = $info["filename"];
$extension = isset($info["extension"]) ? $info["extension"] : "png";
$size = $request->getParameter("size", 512);
$color = trim($request->getParameter("color", "777"), '#');
$filename = "icons/{$iconName}_{$size}_{$color}.{$extension}";
$targetFolder = realpath(".");
$targetLocation = "https://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["SCRIPT_NAME"]) . "/" . $filename;
if (is_file($targetFolder . '/' . $filename)) {
return $response->status(301)->header("Location", $targetLocation);
}
$ttf = realpath(dirname(__FILE__) . "/../webfonts/fontawesome/fontawesome-webfont.ttf");
$characters = (include realpath(dirname(__FILE__) . "/../webfonts/fontawesome/characters.php"));
if (!isset($characters[$iconName])) {
return $response->status(404);
}
$iconChar = html_entity_decode('&#' . $characters[$iconName] . ';');
$canvas = Image::canvas($size, $size);
$canvas->text($iconChar, $size / 2, $size / 2, function ($font) use($ttf, $size, $color) {
$font->file($ttf);
$font->size($size - 2);
$font->color('#' . $color);
$font->align('center');
$font->valign('center');
});
$canvas->save($targetFolder . '/' . $filename);
return $response->status(301)->header("Location", $targetLocation);
}
示例11: savePoster
public function savePoster($filename)
{
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($filename);
$extensions = ['image/jpg' => '.jpg', 'image/jpeg' => '.jpg', 'image/png' => '.png', 'image/gif' => '.gif'];
$extension = '.jpg';
if (!isset($extensions[$mime])) {
$extension = $extensions[$mime];
}
$newFilename = uniqid() . $extension;
$folder = "./images/posters/originals";
// no trailing slash
if (!is_dir($folder)) {
mkdir($folder, 0777, true);
}
$destination = $folder . "/" . $newFilename;
move_uploaded_file($filename, $destination);
$this->poster = $newFilename;
//240x300 80x100
if (!is_dir("./images/posters/300h")) {
mkdir("./images/posters/300h", 0777, true);
}
$img = Image::make($destination);
$img->fit(240, 300);
$img->save("./images/posters/300h/" . $newFilename);
if (!is_dir("./images/posters/100h")) {
mkdir("./images/posters/100h", 0777, true);
}
$img = Image::make($destination);
$img->fit(80, 100);
$img->save("./images/posters/100h/" . $newFilename);
}
示例12: uploadFile
/**
* Upload File with Request
*
* @param User $user
* @param \Illuminate\Http\Request::file() $file
*/
private function uploadFile($user, $file, $type)
{
$client_original_name = $file->getClientOriginalName();
$fileName = time() . '_' . $client_original_name;
//?
$destinationPath = 'uploads/profile';
$path = $destinationPath . '/' . $fileName;
$image = Image::make($file->getRealPath());
switch ($type) {
case 'profile_photo':
$image->fit(128, 128, function ($constraint) {
$constraint->upsize();
})->save($path);
break;
case 'profile_cover':
$image->resize(1440, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save($path);
break;
}
$original_name = pathinfo($client_original_name, PATHINFO_FILENAME);
$file = File::create(['url' => $path, 'original_name' => $original_name, 'type' => $type]);
return $file->id;
}
示例13: image
public function image($display_size, $image_size, $image_path)
{
$max_age_days = 30;
$pixel_density = 2;
$display_sizes = ['sm' => 320, 'md' => 480, 'lg' => 600, 'xl' => 960];
$image_sizes = ['full' => 1, 'half' => 0.5, 'third' => 0.34, 'quarter' => 0.25];
$compressions = ['sm' => 80, 'md' => 80, 'lg' => 80, 'xl' => 80];
$src_path = config('site.assets_path') . '/' . $image_path;
$new_width = (int) ($display_sizes[$display_size] * $pixel_density * $image_sizes[$image_size]);
$compression = $compressions[$display_size];
$colors = (int) Input::get('colors');
// Throw 404 if image does not exist
if (!file_exists($src_path)) {
return response('image not found', 404);
}
$img = Image::make($src_path);
$img->resize($new_width, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
if ($colors > 0) {
$img->limitColors($colors, '#ffffff');
}
$response = Response::make($img->encode(null, $compression), 200);
$response->header('Content-Type', $img->mime());
$response->header('Cache-Control', 'max-age=' . $max_age_days * 24 * 60 * 60 . ', public');
return $response;
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$images = $request->input('images');
$gallery_name = 'gallery_' . time();
$directory = 'uploads/' . $gallery_name . '/';
mkdir($directory, 0755);
$gallery = Gallery::create(['name' => $gallery_name, 'directory' => $directory]);
foreach ($images as $image) {
$url = $image['url'];
$img = Image::make($url);
$img->resize(800, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
preg_match('/\\.[^\\.]+$/i', $url, $ext);
$filename = $directory . time() . $ext[0];
$stream = $img->stream();
$s3 = Storage::disk('s3');
$s3->put($filename, $stream->__toString(), 'public');
$client = $s3->getDriver()->getAdapter()->getClient();
$public_url = $client->getObjectUrl(env('S3_BUCKET'), $filename);
$gallery->images()->create(['url' => $public_url]);
}
$response = ['message' => 'Images successfully uploaded', 'redirect' => url('gallery', $gallery_name)];
return response()->json($response);
}
示例15: upload
public function upload()
{
$file = Input::file('file');
$input = array('image' => $file);
$rules = array('image' => 'image');
$validator = Validator::make($input, $rules);
$imagePath = 'public/uploads/';
$thumbPath = 'public/uploads/thumbs/';
$origFilename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$mimetype = $file->getMimeType();
if (!in_array($extension, $this->whitelist)) {
return Response::json('Supported extensions: jpg, jpeg, gif, png', 400);
}
if (!in_array($mimetype, $this->mimeWhitelist) || $validator->fails()) {
return Response::json('Error: this is not an image', 400);
}
$filename = str_random(12) . '.' . $extension;
$image = ImageKit::make($file);
//save the original sized image for displaying when clicked on
$image->save($imagePath . $filename);
// make the thumbnail for displaying on the page
$image->fit(640, 480)->save($thumbPath . 'thumb-' . $filename);
if ($image) {
$dbimage = new Image();
$dbimage->thumbnail = 'uploads/thumbs/thumb-' . $filename;
$dbimage->image = 'uploads/' . $filename;
$dbimage->original_filename = $origFilename;
$dbimage->save();
return $dbimage;
} else {
return Response::json('error', 400);
}
}