使用CodeIgniter即时调整图像大小 [英] Resizing an image on the fly using CodeIgniter

查看:99
本文介绍了使用CodeIgniter即时调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本,从Dropbox下载一个文件,应该调整该图像的大小,然后拍摄到一个S3桶。

I am working on a script that downloads a file from Dropbox, supposed to resize that image and then shoot it up to an S3 bucket.

由于某种原因,我无法调整图片大小。

For some reason, I can't get the image to resize.

我会收到以下错误:

图片的路径不是正确。
您的服务器不支持处理此类型图像所需的GD函数。

I keep getting the following error:
The path to the image is not correct. Your server does not support the GD function required to process this type of image.

代码库:

Code Base:

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:

Dropbox API DownloadFile:

    public function downloadFile($file) {
        $this->setTokens();
        return $this->conn->getFile($file);
    }

任何人都知道我可能做错了什么?

Anyone know what I might be doing wrong?

推荐答案

不要多次加载image_lib。在自动加载库中添加image_lib并更改

Dont load image_lib multiple times. Add image_lib in autoload libs and change

$this->load->library('image_lib', $config);

$this->image_lib->initialize($config);

这篇关于使用CodeIgniter即时调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆