dongtou9934 2016-06-28 05: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 05: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 访问url时不会自动调用其 Servlet的doGet()
  • ¥15 MATLAB解决问题
  • ¥35 哪位专业人士知道这是什么原件吗?哪里可以买到?
  • ¥15 关于#c##的问题:treenode反序列化后获取不到上一节点和下一节点,Fullpath和Handle报错
  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部