【问题标题】:CodeIgniter Image Manipulation (Resize & Watermark)CodeIgniter 图像处理(调整大小和水印)
【发布时间】:2011-01-15 01:04:02
【问题描述】:

我希望有人可以帮助我。我正在尝试通过表单上传图像,将其调整为 600px,创建 100px 缩略图,然后将水印图像添​​加到 600px 版本,但下面的代码只是创建原始图像的两个版本。

$image = $this->upload->data();
$resized = base_url()."images/artwork/".$image['orig_name'];

//Create 600px version
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 600;
$config['height'] = 600;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);

//Add watermark to 600px version
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['wm_type'] = 'overlay';
$config['wm_overlay_path'] = './images/logo.gif';
$config['wm_vrt_alignment'] = 'middle';
$config['wm_hor_alignment'] = 'center';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$this->image_lib->clear();
unset($config);

//Create 100px unwatermarked thumbnail
$config = array();
$config['source_image'] = $resized;
$config['image_library'] = 'gd2';
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();
unset($config);
$thumbnail = base_url()."images/artwork/".$image['raw_name']."".$image['file_ext'];

echo "<a href=\"".$resized."\"><img src=\"".$thumbnail."\" /></a>";

【问题讨论】:

    标签: php codeigniter image-processing


    【解决方案1】:

    根据此示例,使用 Image Moo 可能会有所帮助:http://ellislab.com/forums/viewthread/162030/#778258

    【讨论】:

      【解决方案2】:

      您似乎没有告诉它为缩略图制作副本。

      //Create 100px unwatermarked thumbnail
      $config = array();
      $config['source_image'] = $resized;
      $config['image_library'] = 'gd2';
      $config['maintain_ratio'] = TRUE;
      $config['create_thumb'] = TRUE;   // Tells it to make a copy called *_thumb.*
      $config['width'] = 100;
      $config['height'] = 100;
      $this->image_lib->initialize($config);
      $this->image_lib->resize();
      $this->image_lib->clear();
      unset($config);
      

      您可能还想输入错误检查代码,以便知道它是否失败以及原因:

      if ( ! $this->image_lib->resize())
      {
          echo $this->image_lib->display_errors();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-06-13
        • 1970-01-01
        • 2012-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多