如何用边框半径重新调整图像大小?

时间:2017-01-05 11:39:41

标签: php html css

使用我的代码上传图片时,会调整大小 - 工作正常。但是我想用圆形的边框半径调整它的大小。

目前它只在200x150重塑。

我想像这样重塑它

style="width:200;
       height:200;
       border: 1px solid rgb(221, 221, 221);
       border-radius: 50%;
       box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.05); "

这是我的index.php



<form method="post" action="" enctype="multipart/form-data" >
<div style="margin-bottom: 15%; padding-left: 30%;">
		

		 
 
 <input type="file" name="image2" class="file" id="imgInp"/>
	  <span  id="topic-box">  <button type="submit" class="btn btn-primary" name="savepic"  >upload</button></span>
</div>
<?php 
    if(isset($_POST['savepic'])){
      $post_image2 = $_FILES['image2']['name'];
      $image_tmp2 = $_FILES['image2']['tmp_name'];
      $kaboom = explode(".", $post_image2); // Split file name into an array using the dot
      $fileExt = end($kaboom); // Now target the last array element to get the file extension
      move_uploaded_file($image_tmp2,"uploads/$post_image2");

			// ---------- Include Universal Image Resizing Function --------
include_once("reshape.php");
$target_file = "uploads/$post_image2";
$resized_file = "uploads/resized_$post_image2";
$wmax = 200;
$hmax = 150;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
// ----------- End Universal Image Resizing Function -----------
			}
   ?>
</form>
&#13;
&#13;
&#13;

这里是reshape.php

&#13;
&#13;
<?php
// Function for resizing jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
    list($w_orig, $h_orig) = getimagesize($target);
    $scale_ratio = $w_orig / $h_orig;
    if (($w / $h) > $scale_ratio) {
           $w = $h * $scale_ratio;
    } else {
           $h = $w / $scale_ratio;
    }
    $img = "";
    $ext = strtolower($ext);
    if ($ext == "gif"){ 
      $img = imagecreatefromgif($target);
    } else if($ext =="png"){ 
      $img = imagecreatefrompng($target);
    } else { 
      $img = imagecreatefromjpeg($target);
    }
    $tci = imagecreatetruecolor($w, $h);
    // imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
    imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
    imagejpeg($tci, $newcopy, 80);
}
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

你需要考虑到你将图像缩小了20%但是边界半径缩小了50%,我会在reshape.php上尝试这行代码

imagejpeg($tci, $newcopy, 50);