PHP implements adding circular logo to the background image Taobao page background image Weibo background image How to set the background for ppt

WBOY
Release: 2016-07-29 08:49:05
Original
1470 people have browsed it

Let’s talk about the steps:

A total of 3 steps:

1. Compress the logo into a square image of a fixed size

2. Convert the logo into a round logo

3. Merge the logo and the background image

Without further ado, let’s go directly to the code:

<?php /**
 * 作者:friker
 * 开发时间:20160516
 * 功能:图片处理
 *
 */
class ImageController extends CI_Controller{

	public function __construct()
	{
		parent::__construct();
		date_default_timezone_set(&#39;Asia/Shanghai&#39;);
		error_reporting( E_ALL&~E_NOTICE&~E_WARNING);
		$this->load->library('curl');
	}

	/**
	 * @todo : 本函数用于 将方形的图片压缩后
	 *         再裁减成圆形 做成logo
	 *         与背景图合并
	 * @return 返回url
	 */
	public function index(){
		//头像
		$headimgurl = 'a.jpg';
		//背景图
		$bgurl = './aa.png';
		$imgs['dst'] = $bgurl;
		//第一步 压缩图片
		$imggzip = $this->resize_img($headimgurl);
		//第二步 裁减成圆角图片
		$imgs['src'] = $this->test($imggzip);
		//第三步 合并图片
		$dest = $this->mergerImg($imgs);
	}

	public function resize_img($url,$path='./'){
		$imgname = $path.uniqid().'.jpg';
		$file = $url;
		list($width, $height) = getimagesize($file); //获取原图尺寸
		$percent = (110/$width);
		//缩放尺寸
		$newwidth = $width * $percent;
		$newheight = $height * $percent;
		$src_im = imagecreatefromjpeg($file);
		$dst_im = imagecreatetruecolor($newwidth, $newheight);
		imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
		imagejpeg($dst_im, $imgname); //输出压缩后的图片
		imagedestroy($dst_im);
		imagedestroy($src_im);
		return $imgname;
	}

	//第一步生成圆角图片
	public function test($url,$path='./'){
		$w = 110;  $h=110; // original size
	    $original_path= $url;
	    $dest_path = $path.uniqid().'.png';
	    $src = imagecreatefromstring(file_get_contents($original_path));
	    $newpic = imagecreatetruecolor($w,$h);
	    imagealphablending($newpic,false);
	    $transparent = imagecolorallocatealpha($newpic, 0, 0, 0, 127);
	    $r=$w/2;
	    for($x=0;$x<br><span>Result display: </span><p><span><img src="http://image.codes51.com/Article/image/20160516/20160516180604_3910.png" alt="PHP implements adding circular logo to the background image Taobao page background image Weibo background image How to set the background for ppt"><br></span></p>
                
                
                <p>
                    The above introduces how to add a circular logo to the background image in PHP, including the logo and background image. I hope it will be helpful to friends who are interested in PHP tutorials. </p>
                <p>
                    </p>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template