2016-06-28 102 views
-1

我不能上傳圖片與笨和得到這個錯誤:在應用程序/庫/ MY_Image_lib.phpimagecopy的()預計參數1是資源,鑑於布爾

A PHP Error was encountered
Severity: Warning
Message: imagecopy() expects parameter 1 to be resource, boolean
given
Filename: libraries/Image_lib.php
Line Number: 1212

功能image_create_gd

public function image_create_gd($path = '', $image_type = '') 
{ 
    if ($path === '') 
    { 
     $path = $this->full_src_path; 
    } 

    if ($image_type === '') 
    { 
     $image_type = $this->image_type; 
    } 

    switch ($image_type) 
    { 
     case 1: 
      if (! function_exists('imagecreatefromgif')) 
      { 
       $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_gif_not_supported')); 
       return FALSE; 
      } 

      return @imagecreatefromgif($path); 
     case 2: 
      if (! function_exists('imagecreatefromjpeg')) 
      { 
       $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_jpg_not_supported')); 
       return FALSE; 
      } 

      return @imagecreatefromjpeg($path); 
     case 3: 
      if (! function_exists('imagecreatefrompng')) 
      { 
       $this->set_error(array('imglib_unsupported_imagecreate', 'imglib_png_not_supported')); 
       return FALSE; 
      } 

      return @imagecreatefrompng($path); 
     default: 
      $this->set_error(array('imglib_unsupported_imagecreate')); 
      return FALSE; 
    } 
} 

功能overlay_watermark應用/庫/ MY_Image_lib.php(行號1212):

public function overlay_watermark() 
{ 
    if (! function_exists('imagecolortransparent')) 
    { 
     $this->set_error('imglib_gd_required'); 
     return FALSE; 
    } 

    // Fetch source image properties 
    $this->get_image_properties(); 

    // Fetch watermark image properties 
    $props  = $this->get_image_properties($this->wm_overlay_path, TRUE); 
    $wm_img_type = $props['image_type']; 
    $wm_width = $props['width']; 
    $wm_height = $props['height']; 

    // Create two image resources 
    $wm_img = $this->image_create_gd($this->wm_overlay_path, $wm_img_type); 
    $src_img = $this->image_create_gd($this->full_src_path); 

    // Reverse the offset if necessary 
    // When the image is positioned at the bottom 
    // we don't want the vertical offset to push it 
    // further down. We want the reverse, so we'll 
    // invert the offset. Same with the horizontal 
    // offset when the image is at the right 

    $this->wm_vrt_alignment = strtoupper($this->wm_vrt_alignment[0]); 
    $this->wm_hor_alignment = strtoupper($this->wm_hor_alignment[0]); 

    if ($this->wm_vrt_alignment === 'B') 
     $this->wm_vrt_offset = $this->wm_vrt_offset * -1; 

    if ($this->wm_hor_alignment === 'R') 
     $this->wm_hor_offset = $this->wm_hor_offset * -1; 

    // Set the base x and y axis values 
    $x_axis = $this->wm_hor_offset + $this->wm_padding; 
    $y_axis = $this->wm_vrt_offset + $this->wm_padding; 

    // Set the vertical position 
    if ($this->wm_vrt_alignment === 'M') 
    { 
     $y_axis += ($this->orig_height/2) - ($wm_height/2); 
    } 
    elseif ($this->wm_vrt_alignment === 'B') 
    { 
     $y_axis += $this->orig_height - $wm_height; 
    } 

    // Set the horizontal position 
    if ($this->wm_hor_alignment === 'C') 
    { 
     $x_axis += ($this->orig_width/2) - ($wm_width/2); 
    } 
    elseif ($this->wm_hor_alignment === 'R') 
    { 
     $x_axis += $this->orig_width - $wm_width; 
    } 

    // Build the finalized image 
    if ($wm_img_type === 3 && function_exists('imagealphablending')) 
    { 
     @imagealphablending($src_img, TRUE); 
    } 

    // Set RGB values for text and shadow 
    $rgba = imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp); 
    $alpha = ($rgba & 0x7F000000) >> 24; 

    // make a best guess as to whether we're dealing with an image with alpha transparency or no/binary transparency 
    if ($alpha > 0) 
    { 
     // copy the image directly, the image's alpha transparency being the sole determinant of blending 
/*No.1212*/ imagecopy($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height); //****Line number is 1212**** 
    } 
    else 
    { 
     // set our RGB value from above to be transparent and merge the images with the specified opacity 
     imagecolortransparent($wm_img, imagecolorat($wm_img, $this->wm_x_transp, $this->wm_y_transp)); 
     imagecopymerge($src_img, $wm_img, $x_axis, $y_axis, 0, 0, $wm_width, $wm_height, $this->wm_opacity); 
    } 

    // We can preserve transparency for PNG images 
    if ($this->image_type === 3) 
    { 
     imagealphablending($src_img, FALSE); 
     imagesavealpha($src_img, TRUE); 
    } 

    // Output the image 
    if ($this->dynamic_output === TRUE) 
    { 
     $this->image_display_gd($src_img); 
    } 
    elseif (! $this->image_save_gd($src_img)) // ... or save it 
    { 
     return FALSE; 
    } 

    imagedestroy($src_img); 
    imagedestroy($wm_img); 

    return TRUE; 
} 

這是watermark配置:

$config = array(
    'wm_text' => 'google.com', 
    'source_image' => $file['full_path'], 
    'maintain_ration' => false, 
    'wm_type' => 'overlay', 
    'wm_overlay_path' => './files/image/watermark.png', 
); 
$this->image_lib->initialize($config); 
$this->image_lib->watermark(); 
$this->image_lib->clear(); 

回答

0

嗯,錯誤陳述:$src_img是一個布爾值,而應該是一種資源。 在你的函數image_create_gd()中,你返回一個布爾值。

$src_img = $this->image_create_gd($this->full_src_path); //image_create_gd() return true or false 
+0

如何修改碼? – user837032

+1

解決方案是什麼? – user837032

+0

解決方法是將函數image_create_gd()更改爲不返回布爾值,而是返回資源。 – Matheno

相關問題