ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – 使用CodeIgniter动态调整图像大小

2019-10-07 13:37:28  阅读:166  来源: 互联网

标签:php codeigniter image-manipulation


我正在编写一个从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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有