【问题标题】:create thumbnails using for loop使用 for 循环创建缩略图
【发布时间】:2009-09-15 05:26:43
【问题描述】:

如何在 Codeigniter 中使用 for 循环从解压缩的图像文件夹中创建缩略图?

【问题讨论】:

    标签: php codeigniter thumbnails


    【解决方案1】:

    不 这样会更好

    config['image_library'] = 'gd2';
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 100;
    $config['height'] = 100;
    $this->load->library('image_lib', $config);
    foreach ($images AS $file) {
        $config['source_image'] = $file;
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
    }
    

    【讨论】:

      【解决方案2】:

      加载目录助手:

      $this->load->helper('directory');
      

      映射目录:

      $images = directory_map('./directoryRelativeToIndexDotPhp/');
      

      现在您在 $images 中创建了一个文件数组,为 image_lib 类设置一个配置数组并循环遍历它们,调整图像大小:

      $config['image_library'] = 'gd2';
      $config['maintain_ratio'] = TRUE;
      $config['width'] = 100;
      $config['height'] = 100;
      foreach ($images AS $file) {
          $config['source_image'] = $file;
          $this->load->library('image_lib', $config);
          $this->image_lib->resize();
      }
      

      未经测试,但这应该会给您一个良好的开端。在调整大小之前,您可能需要检查文件是否实际上是图像。

      查看图像处理库http://codeigniter.com/user_guide/libraries/image_lib.html的文档

      【讨论】:

        猜你喜欢
        • 2015-08-21
        • 1970-01-01
        • 2012-05-10
        • 2014-06-16
        • 1970-01-01
        • 1970-01-01
        • 2021-10-20
        • 2017-12-19
        • 1970-01-01
        相关资源
        最近更新 更多