在 codeigniter 中一次制作 2 个缩略图

发布于 2024-08-31 06:16:44 字数 118 浏览 2 评论 0原文

谁能告诉我如何在 codeigniter 中创建不同大小和位置的相同图像的 2 个不同缩略图。我创建了一个上传功能和另一个缩略图生成功能,它工作正常,但无法弄清楚如何同时相应地创建 2 个不同的缩略图。任何帮助将不胜感激。

can anyone tell me how to create 2 different thumbnails of same images with different sizes and location in codeigniter. I have created a upload function and another thumbnail generation function, it works fine but can't sort out how to create 2 different thumbnail at accordingly at once. any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南烟 2024-09-07 06:16:44

其实很简单...

function create_thumbs()
{
    $this->load->library('image_lib');

    $path = "path/to/image/";

    $source_image = "original.jpg";
    $medium_image = "medium.jpg";
    $small_image = "small.jpg";

    // Resize to medium

    $config['source_image'] = $path.$source_image;
    $config['new_image'] = $path.$medium_image;
    $config['width'] = 200;
    $config['height'] = 200;

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

    if ( ! $this->image_lib->resize())
    {
        // an error occured
    }

    // Keep the same source image

    $config['new_image'] = $path.$small_image;
    $config['width'] = 50;
    $config['height'] = 50;

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

    if ( ! $this->image_lib->resize())
    {
        // an error occured
    }
}

It's actually pretty easy...

function create_thumbs()
{
    $this->load->library('image_lib');

    $path = "path/to/image/";

    $source_image = "original.jpg";
    $medium_image = "medium.jpg";
    $small_image = "small.jpg";

    // Resize to medium

    $config['source_image'] = $path.$source_image;
    $config['new_image'] = $path.$medium_image;
    $config['width'] = 200;
    $config['height'] = 200;

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

    if ( ! $this->image_lib->resize())
    {
        // an error occured
    }

    // Keep the same source image

    $config['new_image'] = $path.$small_image;
    $config['width'] = 50;
    $config['height'] = 50;

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

    if ( ! $this->image_lib->resize())
    {
        // an error occured
    }
}
椵侞 2024-09-07 06:16:44

所以你有一个thumbnail_generator函数,并说它接受参数original_file_name、new_file_name和thumbnail_size。

只需调用两次即可!

thumbnail_generator( original_file.jpg, new_file_sm.jpg, 300 );
thumbnail_generator( original_file.jpg, new_file_xsm.jpg, 150 );

So you have a thumbnail_generator function, and say it takes parameters original_file_name, new_file_name, and thumbnail_size.

Just call it twice!

thumbnail_generator( original_file.jpg, new_file_sm.jpg, 300 );
thumbnail_generator( original_file.jpg, new_file_xsm.jpg, 150 );
染火枫林 2024-09-07 06:16:44

只需对上面的答案稍加修改即可。将其添加到函数的开头,

$this->load->library('image_lib');
$this->image_lib->clear();

需要清除以前的配置

Just a little modification in the above answer. Add this in the beginning of your function

$this->load->library('image_lib');
$this->image_lib->clear();

the previous config needs to be cleared

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文