dongtou9934 2016-06-28 13:11
浏览 121
已采纳

imagecopy()期望参数1是资源,给定布尔值

I can't upload image with codeigniter and get this error:

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

function image_create_gd at application/libraries/MY_Image_lib.php

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;
    }
}

function overlay_watermark application/libraries/MY_Image_lib.php (Line number 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;
}

This is watermark config:

$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();
  • 写回答

1条回答 默认 最新

  • dqybjj3497 2016-06-28 13:16
    关注

    Well, as the error stated: $src_img is a boolean, while it should be a resource. In your function image_create_gd() you return a boolean.

    $src_img = $this->image_create_gd($this->full_src_path); //image_create_gd() return true or false
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题