2016-10-13 83 views
0

我在本地主機上使用codeigniter 3.1。 我想裁剪圖像,但裁剪不工作。只調整工作。所以我啓用了Gd2 php擴展。Codeigniter圖像裁剪不起作用

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)中的圖像但不裁剪。

+0

能否請你解釋更多更好地瞭解 –

+0

你想要做什麼。 –

+0

對於emaple如果圖像大小1000X700,那麼我想從原始圖像尺寸裁剪'300x50'。我不想調整大小。 @MuhammadUsman – Mehur

回答

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

+0

讓我知道如果面對任何問題 –

+0

http://stackoverflow.com/questions/3325106/how-to-crop-image-in-codeigniter –

+0

在Github的好圖書館https://jenssegers.com/31/ codeigniter-resizing-and-cropping-images-on-the-fly –