使用 PHP 在图像上圆角?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/609109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:15:49  来源:igfitidea点击:

Rounded corners on images using PHP?

phprounded-corners

提问by Dineshaws

Does anyone know how to make a image have rounded corners using a PHP script?

有谁知道如何使用 PHP 脚本使图像具有圆角?

回答by Salman A

This script shows how to apply rounded corners to images using PHP and GD Library. It is as simple as drawing four quadrants of a circle over the four corners of the image. The circle itself has to be transparent.

此脚本显示如何使用 PHP 和 GD 库将圆角应用于图像。它就像在图像的四个角上绘制圆形的四个象限一样简单。圆圈本身必须是透明的。

This script, on the other hand, generates rounded corner graphicsfor HTML or CSS based solutions. It generates the four corners that you can overlay over an image using CSS positioning or HTML tables.

另一方面,此脚本为基于 HTML 或 CSS 的解决方案生成圆角图形。它生成四个角,您可以使用 CSS 定位或 HTML 表将其覆盖在图像上。

回答by Quique

It can be done using php-gd, but I ended up passing that task to the browser, using CSS:

它可以使用 php-gd 完成,但我最终使用 CSS 将该任务传递给浏览器:

<img src="photo.jpg" width="42" height="42" alt="My cool photo" style="border-radius: 15px; -moz-border-radius: 15px;" />

<img src="photo.jpg" width="42" height="42" alt="我的酷照片" style="border-radius: 15px; -moz-border-radius: 15px;" />

回答by php rounded corners

There are a lot of options available, you can find them using Google. The easiest way though is using the Thumbnailer. It's as simple as two lines of code:

有很多可用的选项,您可以使用 Google 找到它们。最简单的方法是使用Thumbnailer。它就像两行代码一样简单:

// make an object
$th=new Thumbnailer("your-photo.jpg");

// create a 120x90 thumb and round its corners
$th->thumbFixed(120,90)->round()->save("your-thumb.jpg");

Fun it is, isn't it? :) There are a lot of other options available. The corners will be antialiased.

很有趣,不是吗?:) 还有很多其他选项可用。角落将被抗锯齿。

回答by Dineshaws

Download easyphpthumbnail.class.php from this link

从此链接下载easyphpthumbnail.class.php

from this you can resize and convert image into rounded image.

由此您可以调整图像大小并将其转换为圆形图像。

in below example image is converted into transparent circle image.

在下面的示例图像中转换为透明圆形图像。

include_once('easyphpthumbnail.class.php');
$source = 'demo.jpg';
$width      =  100;
$height     =  100;    
$thumb = new easyphpthumbnail;
$thumb -> Thumbheight = $width;
$thumb -> Thumbwidth = $height;
$thumb -> Backgroundcolor = '#FFFFFF';
$thumb -> Clipcorner = array(2,50,0,1,1,1,1);
$thumb -> Maketransparent = array(1,0,'#FFFFFF',10);   
$thumb -> Createthumb($source);

回答by Dineshaws

You can look at https://www.phpcontext.com/thumbnailer/. There's a script for creating nice rounded corner thumbs with PHP. They are antialiased too.

您可以查看https://www.phpcontext.com/thumbnailer/。有一个脚本可以用 PHP 创建漂亮的圆角拇指。它们也是抗锯齿的。

回答by slacy

Instead of modifying the image, why not just wrap it in some HTML that has images at each corner that overlay the original to provide the appearance of rounded corners?

与其修改图像,不如将其包装在一些 HTML 中,每个角都有图像,覆盖原始图像以提供圆角的外观?

By doing the image editing in your .php script, you're going to put undue load on your web server, and that means your application won't scale well.

通过在您的 .php 脚本中进行图像编辑,您将给您的 Web 服务器带来不必要的负载,这意味着您的应用程序将无法很好地扩展。

回答by ryonlife

GD is great for image manipulation, but it would be much easier for you and much easier on your server if you used CSS.

GD 非常适合图像处理,但如果您使用 CSS,它对您来说会容易得多,而且在您的服务器上也会容易得多。

Here's a great tutorial for some cool image effects using CSS:

这是使用 CSS 的一些很酷的图像效果的很棒的教程:

http://www.webdesignerwall.com/tutorials/css-decorative-gallery/

http://www.webdesignerwall.com/tutorials/css-decorative-gallery/

For modern browsers, you can do it in pure CSS:

对于现代浏览器,您可以使用纯 CSS 来实现:

http://www.css3.info/preview/rounded-border/

http://www.css3.info/preview/rounded-border/

A couple of other noteworthy ones:

其他几个值得注意的:

http://www.spiffycorners.com/

http://www.spiffycorners.com/

http://www.html.it/articoli/niftycube/index.html

http://www.html.it/articoli/niftycube/index.html

回答by php rounded corners

its easy to create some rounded thumbsusing php, just use Thumbnailer :)

使用 php很容易创建一些圆形的拇指,只需使用 Thumbnailer :)