php – 使用CodeIgniter动态调整图像大小
作者:互联网
我正在编写一个从Dropbox下载文件的脚本,应该调整该图像的大小,然后将其拍摄到S3存储桶.
出于某种原因,我无法让图像调整大小.
我一直收到以下错误:
图像的路径不正确.
您的服务器不支持处理此类图像所需的GD功能.
代码库:
public function resize_test() {
$postcard_assets = $this->conn->getPostcardDirContent("folder_name", "Photos", TRUE);
foreach($postcard_assets['contents'] as $asset) {
$file = pathinfo($asset['path']);
$original_file = $this->conn->downloadFile($asset['path']);
$raw_file = sha1($file['basename']);
$s3_file_name = "1_{$raw_file}.{$file['extension']}";
$this->resize_photo($original_file);
$this->s3->putObject($s3_file_name, $original_file, 's3-bucket-name', 'public-read');
$s3_check = $this->s3->getObjectInfo($s3_file_name, 's3-bucket-name');
if($s3_check['content-length'] > 0) {
krumo($s3_check);
exit();
}
}
}
private function resize_photo($photo) {
$config['image_library'] = 'imagemagick';
$config['source_image'] = $photo;
$config['maintain_ratio'] = TRUE;
$config['width'] = 640;
$config['height'] = 480;
$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()) {
exit($this->image_lib->display_errors());
}
}
Dropbox API DownloadFile:
public function downloadFile($file) {
$this->setTokens();
return $this->conn->getFile($file);
}
谁知道我可能做错了什么?
解决方法:
不要多次加载image_lib.在autoload库中添加image_lib并进行更改
$this->load->library('image_lib', $config);
至
$this->image_lib->initialize($config);
标签:php,codeigniter,image-manipulation 来源: https://codeday.me/bug/20191007/1867376.html