gpt4 book ai didi

php - 如何使用边框半径调整图像大小?

转载 作者:行者123 更新时间:2023-11-28 04:35:50 25 4
gpt4 key购买 nike

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

目前它只能在 200x150 中 reshape 。

我想这样 reshape 它

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>

这里是reshape.php

<?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);
}
?>

最佳答案

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

imagejpeg($tci, $newcopy, 50);

关于php - 如何使用边框半径调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41484127/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com