zoukankan      html  css  js  c++  java
  • 方角图片转换成圆角图片

    <?php
    $start_time = time();
    get_squre_circle_pic('logo.jpg');
    $end_time = time();
    echo date('i:s', $end_time - $start_time);

    function get_squre_circle_pic($url,$path='./') {
    $squre_url = resize_img($url, $path);
    $w = 100; $h=100; // 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);
    imagepng($newpic, $dest_path);
    imagedestroy($newpic);
    imagedestroy($src);
    // unlink($url);
    return $dest_path;
    }

    function resize_img($url,$path='./'){
    $square_url = $path.uniqid().'.jpg';
    $file = $url;
    list($width, $height) = getimagesize($file); //获取原图尺寸
    $percent = (100/$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, $square_url); //输出压缩后的图片
    imagedestroy($dst_im);
    imagedestroy($src_im);
    return $square_url;
    }
  • 相关阅读:
    cookie操作
    css加载动画...
    三目运算符的运用
    遍历对象长度
    2年
    相亲

    股市周期
    功利心
    思考笔记
  • 原文地址:https://www.cnblogs.com/phonecom/p/7418773.html
Copyright © 2011-2022 走看看