将圆角添加到jpeg文件 [英] Add round corners to a jpeg file

查看:108
本文介绍了将圆角添加到jpeg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向jpeg文件中添加圆角,但是问题是在添加圆角后,我得到了黑色的背景色.我无法以某种方式将其更改为任何其他颜色(白色,透明,红色).它只是简单地显示图像带有圆角的黑色背景.

I am trying to add round corners to a jpeg file, but the problem is that after adding round corners, I am getting a black background color. Somehow I am not able to change it to any other color (white, transparent, red). It just simply shows black background where the image has rounded corners.

我正在使用的代码是:

<?php

    $image = new Imagick('example.jpg');
    $image->setBackgroundColor("red");
    $image->setImageFormat("jpg");
    $image->roundCorners(575,575);
    $image->writeImage("rounded.jpg");
    header('Content-type: image/jpeg');
    echo $image;

?>

我不能使用png,因为jpeg文件很大,大约5 MB,所以即使使用png,即使png添加了透明的圆角,文件大小也将达到26 MB.

I cannot use png as the jpeg files are huge, about 5 MB, so if I used png, the file size would go up to 26 MB, even though the png adds transparent round corners.

我正在使用的IMagick版本是:

Also the IMagick version that i am using is:

ImageMagick 6.6.2-10 2010-06-29 Q16 http://www.imagemagick.org 

输出(生成的图像)​​也将被打印出来,所以我不知道css是否可以在这里工作.

Also the output(image generated) will get printed so I don't know if css will work over here.

对不起,我正在尝试从不具有圆角的现有jpeg文件中创建一个带有圆角的新jpeg文件,这实际上是从相机拍摄的照片,因此颜色多种/太多,因此我也不能使用gif.

Sorry, I am trying to actually create a new jpeg file with rounded corners from an already existing jpeg file that doesn't have round corners this is actually a photograph taken from a camera, so there are multiple/too many colors so I can't use gif as well.

我的网站也只会生成圆角图像,然后由站点管理员使用FTP程序下载该图像,然后使用系统软件进行打印,因此简而言之,我的网站将不会打印该图像图片,而只是生成它

Also my site will only just generate the round corner image then afterwards it will get downloaded using a FTP program by the admin of the site and then using a system software will get printed, so in short my website will not be printing the image but rather just generate it

推荐答案

尝试一下:

<?php 
$input = 'example.jpg';
$size = getimagesize($input);
$background = new Imagick();
$background->newImage($size[0], $size[1], new ImagickPixel('red'));
$image = new Imagick($input);
$image->setImageFormat("png");
$image->roundCorners(575,575);
$image->compositeImage($background, imagick::COMPOSITE_DSTATOP, 0, 0);
$image->writeImage("rounded.jpg");
?>

这篇关于将圆角添加到jpeg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆