我正在使用 laravel 4 ,我安装了 干预图片包 。当我在我的代码中使用它时,方法 - >调整大小, - >移动等等...我有错误:
Intervention \ Image \ Exception \ NotReadableException
图片来源不可读
open: /Applications/MAMP/htdocs/myNameProject/vendor/intervention/image/src/Intervention/Image/AbstractSource.php
break;
case $this->isFilePath():
return $this->initFromPath($this->data);
break;
default:
throw new Exception\NotReadableException("Image source not readable");
break;
}
我也在MAC OS上使用 MAMP和Sublime Text 3,如果它可以帮到你。
这是我控制器中的代码:
public function upload() {
//***** UPLOAD FILE (on server it's an image but an Url in Database *****//
// get the input file
$file = Image::make('url_Avatar');
//set a register path to the uploaded file
$destinationPath = public_path().'upload/';
//have client extension loaded file and set a random name to the uploaded file, produce a random string of length 32 made up of alphanumeric characters [a-zA-z0-9]
$filename = $destinationPath . '' . str_random(32) . '.' . $file->getClientOriginalExtension();
//$file->move($destinationPath,$filename);
//set $file in order to resize the format and save as an url in database
$file= Image::make($image->getRealPath())->resize('200','200')->save('upload/'.$filename);
//*****VALIDATORS INPUTS and RULES*****
$inputs = Input::all();
$rules = array(
'pseudo' => 'required|between:1,64|unique:profile,pseudo',
//urlAvatar is an url in database but we register as an image on the server
'url_Avatar' => 'required|image|min:1',
);
(我没有向您展示我的视图的重定向,但它对我控制器的这一部分工作正常)
这是我的表单代码(使用刀片laravel模板):
@extends('layout.default')
@section('title')
Name Of My Project - EditProfile
@stop
@section('content')
{{Form::open(array('url'=>'uploadAvatar','files' => true))}}
<p>
{{Form::label('pseudo','pseudo (*): ')}}
{{Form::text('pseudo',Input::old('nom'))}}
</p>
@if ($errors->has('pseudo'))
<p class='error'> {{ $errors->first('pseudo')}}</p>
@endif
<br>
<br>
<p>
{{Form::label('url_Avatar','Avatar: ')}}
{{Form::file('url_Avatar',Input::old('Url_Avatar'))}}
</p>
@if ($errors->has('url_Avatar'))
<p class='error'> {{ $errors->first('url_Avatar')}}</p>
@endif
<br>
<br>
<p>
{{Form::submit('Validate your avatar')}}
</p>
{{Form::close()}}
@stop
当然,我已在官方网站 image.intervention.io/getting_started/installation strong>(url)。
如何让我的文件“可读”?或解决此错误?
答案 0 :(得分:15)
改变这个:
$file = Image::make('url_Avatar');
对此:
$file = Input::file('url_Avatar');
// ...
$filename = '...';
Image::make($file->getRealPath())->resize('200','200')->save($filename);
答案 1 :(得分:1)
我有同样的问题。当我更改图像驱动程序时,一切正常。
尝试将图像驱动程序从app / config / packages / intervention / image / config.php从GD更改为Imagick
如果找不到配置文件,请尝试运行以下命令:
在Laravel 5中发布配置
$ php artisan vendor:publish --provider =“Intervention \ Image \ ImageServiceProviderLaravel5”
在Laravel 4中发布配置
$ php artisan config:发布干预/图像
配置文件中的示例内容:
return array(
/*
|--------------------------------------------------------------------------
| Image Driver
|--------------------------------------------------------------------------
|
| Intervention Image supports "GD Library" and "Imagick" to process images
| internally. You may choose one of them according to your PHP
| configuration. By default PHP's "GD Library" implementation is used.
|
| Supported: "gd", "imagick"
|
*/
'driver' => 'imagick'
);
答案 2 :(得分:0)
如果您在公共路径中使用子文件夹,请使用chmod更改该文件夹的权限
例如
cd public;
chmod -Rv 755 public/{your_path_name};
运行
man chmod;
了解更多详情
答案 3 :(得分:0)
这在解决方案中
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false
func playmyVideo(myString: String) {
let bundle: Bundle = Bundle.main
let videoPlayer: String = bundle.path(forResource: myString, ofType: "mov")!
let movieUrl : NSURL = NSURL.fileURL(withPath: videoPlayer) as NSURL
print(movieUrl)
viewVideo.playVideoWithURL(url: movieUrl)
}
@IBAction func normalPressed(_ sender: Any) {
playmyVideo(myString: "normal")
}
@IBAction func forwardPressed(_ sender: Any) {
playmyVideo(myString: "fast")
}
class VideoPlay: UIView {
private var player : AVPlayer!
private var playerLayer : AVPlayerLayer!
init() {
super.init(frame: CGRect.zero)
self.initializePlayerLayer()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.initializePlayerLayer()
self.autoresizesSubviews = false
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initializePlayerLayer()
}
private func initializePlayerLayer() {
playerLayer = AVPlayerLayer()
playerLayer.backgroundColor = UIColor.clear.cgColor
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
self.layer.addSublayer(playerLayer)
playerLayer.frame = UIScreen.main.bounds
}
func playVideoWithURL(url: NSURL) {
player = AVPlayer(url: url as URL)
player.isMuted = false
playerLayer.player = player
player.play()
loopVideo(videoPlayer: player)
}
func toggleMute() {
player.isMuted = !player.isMuted
}
func isMuted() -> Bool
{
return player.isMuted
}
func loopVideo(videoPlayer: AVPlayer) {
NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil, queue: nil) { notification in
let t1 = CMTimeMake(5, 100);
self.player.seek(to: t1)
videoPlayer.seek(to: kCMTimeZero)
self.player.play()
}
}
}