douluanji8752 2013-04-23 11:33
浏览 58
已采纳

使用codeigniter图像水印库时,像素消失

I have been tasked with overlaying a photo on to a newspaper-esque image where the photo is of a person and they are meant to be the photo on the front of a newspaper.

I used codeigniter image library to watermark the template with the photo. It works fine but it distorts or removes some of the pixels in the photo when its overlayed

You can see it in the top left of the photo here-

enter image description here

I am also resizing the image up as its 500 px and the space for the image in the template is around 1400px

Here is the code i am using to overlay the image

private function overlay($template, $source_image)
    {
        echo $template;
        // $config = array();
        $config['source_image'] = $template;
        $config['image_library'] = 'gd2';
        $config['wm_type'] = 'overlay';
        $config['wm_overlay_path'] = $source_image;
        $config['wm_vrt_alignment'] = 'top';
        $config['wm_hor_alignment'] = 'left';
        $config['wm_hor_offset'] = '18px';
        $config['wm_vrt_offset'] = '843px';
        $config['quality'] = '100%';
        $this->image_lib->initialize($config);
        $result = $this->image_lib->watermark();


        if($result){
            return $result;
        }
        else
        {
            echo $this->image_lib->display_errors();
            return false;
        }

    }
  • 写回答

2条回答 默认 最新

  • douwulu2576 2013-04-25 22:10
    关注

    Since there was no answer i ended up using native php functions which worked.

    imgpng has a 2nd parameter if you wish to saved the file to your server instead. Since they were being printed on a click of the button i just prompted a browser download

    private function overlay2($template, $source_image)
    {
    
    
    
        $src  = imagecreatefromjpeg($source_image);
        $dest = imagecreatefrompng($template);
    
        imagecopymerge($dest,$src, 90, 910, 0, 0, 1511, 1075, 100); //have to play with these numbers for it to work for you, etc.
    
    
    
        header('Content-Disposition: Attachment;filename=newspaper.png'); 
        header('Content-type: image/png'); 
    
        imagepng($dest);
    
        imagedestroy($dest);
        imagedestroy($src);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误