【问题标题】:Codeigniter image cropping is not workingCodeigniter 图像裁剪不起作用
【发布时间】:2016-10-14 03:29:35
【问题描述】:

我在本地主机上使用 codeigniter 3.1。 我正在尝试裁剪图像,但裁剪不起作用。仅调整大小工作。所以我启用了Gd2 php 扩展。

1.

public function do_crop($filename)
{
    $this->load->library('image_lib');
    $source_path =  'uploads/' . $filename;
    $target_path =  'uploads/thumb/'.$filename;

    $config = array(
        'image_library' => 'gd2',
        'source_image' => $source_path,
        'new_image' => $target_path,
        'maintain_ratio' => FALSE,
        'x_axis' => 300,
        'y_axis' => 100,
    );
    $this->image_lib->initialize($config);
} 

图像尺寸 = 1000X700

输出结果与原图大小相同1000X700

2.

public function do_crop($filename)
    {
        $this->load->library('image_lib');
        $source_path =  'uploads/' . $filename;
        $target_path =  'uploads/thumb/'.$filename;

        $config = array(
            'image_library' => 'gd2',
            'source_image' => $source_path,
            'new_image' => $target_path,
            'maintain_ratio' => FALSE,
            'width' => 300,
            'height' => 300,
            'x_axis' => 350,
             'y_axis' => 50
        );
        $this->image_lib->initialize($config);
    } 

图像尺寸 = 1000X700

第二个示例仅调整 (300x300) 图像的大小但未裁剪。

【问题讨论】:

  • 能否请您多解释一下以便更好地理解
  • 你到底想做什么。
  • 对于 emaple,如果图像尺寸为 1000X700,那么我想从原始图像尺寸裁剪 300x50。我不想调整大小。 @MuhammadUsman

标签: php image codeigniter


【解决方案1】:
$config = array(
'source_image' => $upload_path.$image_data['file_name'],
'maintain_ratio' => FALSE,
'width' => 220,
'height' => 150,
'x_axis' => 350,
'y_axis' => 50
);
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();

更多详情请See Here 欲了解更多信息Check Here

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多