PHP
·
发表于 5年以前
·
阅读量:8296
±¾ÎÄʵÀý½²ÊoÁËphpʵÏÖ±³¾°Í¼ÉÏÌi¼ÓÔ²ÐÎlogoͼ±eµÄ½¨¡£*ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
˵һϲ½Öe£º
×ܹ²*Ö 3 ²½£º
1. ѹËologo ³É¹Ì¶¨´oСµÄ*½ÐÎͼƬ
2. ½«logo ת³ÉÔ²ÐÎlogo
3. ½«logoÓe±³¾°Í¼ºÏ²¢
*Ï»°²»¶a˵£¬Ö±½ÓÉÏ´uÂe£º
<?php
/**
* ×÷Õߣºfriker
* ¿ª*¢Ê±¼a£º20160516
* ¹¦ÄÜ£ºÍ¼Æ¬´¦Ài
*
*/
class ImageController extends CI_Controller{
public function __construct()
{
parent::__construct();
date_default_timezone_set('Asia/Shanghai');
error_reporting( E_ALL&~E_NOTICE&~E_WARNING);
$this->load->library('curl');
}
/**
* @todo : ±¾º¯ÊýÓÃÓÚ ½«*½ÐεÄͼƬѹËoºo
* Ôٲüo³ÉÔ²ÐÎ ×o³Élogo
* Óe±³¾°Í¼ºÏ²¢
* @return *µ»Øurl
*/
public function index(){
//Í*Ïñ
$headimgurl = 'a.jpg';
//±³¾°Í¼
$bgurl = './aa.png';
$imgs['dst'] = $bgurl;
//µÚÒ»²½ ѹËoͼƬ
$imggzip = $this->resize_img($headimgurl);
//µÚ¶þ²½ ²Ã¼o³ÉÔ²½ÇͼƬ
$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);
//Ëo*ųߴç
$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); //Êa³oѹËoºoµÄͼƬ
imagedestroy($dst_im);
imagedestroy($src_im);
return $imgname;
}
//µÚÒ»²½Éu³ÉÔ²½ÇͼƬ
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<$w;$x++)
for($y=0;$y<$h;$y++){
$c = imagecolorat($src,$x,$y);
$_x = $x - $w/2;
$_y = $y - $h/2;
if((($_x*$_x) + ($_y*$_y)) < ($r*$r)){
imagesetpixel($newpic,$x,$y,$c);
}else{
imagesetpixel($newpic,$x,$y,$transparent);
}
}
imagesavealpha($newpic, true);
// header('Content-Type: image/png');
imagepng($newpic, $dest_path);
imagedestroy($newpic);
imagedestroy($src);
unlink($url);
return $dest_path;
}
//php ºÏ²¢Í¼Æ¬
public function mergerImg($imgs,$path='./') {
$imgname = $path.rand(1000,9999).uniqid().'.jpg';
list($max_width, $max_height) = getimagesize($imgs['dst']);
$dests = imagecreatetruecolor($max_width, $max_height);
$dst_im = imagecreatefrompng($imgs['dst']);
imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height);
imagedestroy($dst_im);
$src_im = imagecreatefrompng($imgs['src']);
$src_info = getimagesize($imgs['src']);
imagecopy($dests,$src_im,270,202,0,0,$src_info[0],$src_info[1]);
imagedestroy($src_im);
// var_dump($imgs);exit;
// header("Content-type: image/jpeg");
imagejpeg($dests,$imgname);
// unlink($imgs['dst']);
unlink($imgs['src']);
return $imgname;
}
}
½a¹uչʾ£º
¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶PHPͼÐÎÓeͼƬ²Ù×÷¼¼ÇÉ»a×Ü¡¡¢¡¶[PHP»u±¾Ói¨ÈeÃŽ̳Ì](http://www.jb51.net/Special/348.htm)¡¡¢¡¶[PHPÔËËaÓeÔËËauÓè×ܽa](http://www.jb51.net/Special/357.htm)¡¡¢¡¶phpÃaeÏo¶ÔÏo³ÌÐoÉe¼ÆÈeÃŽ̡̳¡¢¡¶PHPÍøÂç±a³Ì¼¼ÇÉ×ܽa¡¡¢¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶[php×Öu´®(string)Óè×ܽa](http://www.jb51.net/Special/47.htm)¡¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£