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;
    }
  • 相关阅读:
    JAVA垃圾收集器
    ora-12154
    获取IE浏览器关闭事件
    ajax 页面请求后,jsp页面定位
    poi 导出excel 异常处理方式--曲线救国法
    如何设计出高可用的分布式架构
    Java知识点整理(二)
    spring cloud & dubbo
    Spring Autowired原理
    如何更好的使用JAVA线程池
  • 原文地址:https://www.cnblogs.com/phonecom/p/7418773.html
Copyright © 2011-2022 走看看