Php 如何在图像周围添加图像边框?
有没有简单的方法在图像周围添加图像边框 原因是我想在图像周围创建阴影效果 这些图像作为缩略图加载,并且是110x75像素。。。我正在考虑创建一个阴影边框,但不知道如何将其添加到图像周围,有人知道方法吗Php 如何在图像周围添加图像边框?,php,html,image,Php,Html,Image,有没有简单的方法在图像周围添加图像边框 原因是我想在图像周围创建阴影效果 这些图像作为缩略图加载,并且是110x75像素。。。我正在考虑创建一个阴影边框,但不知道如何将其添加到图像周围,有人知道方法吗 PHP首选…您可以使用GD库或ImageMagick在PHP中更改实际图像,但如果仅在网页上需要,也可以在CSS中实现类似效果 这里有一个关于如何使用PHP和GD的完整教程: 如果要使用PHP,请尝试使用PHP GD库: 使用CSS将是一个更容易的选择,使用border属性。您需要使用CSS来
PHP首选…您可以使用GD库或ImageMagick在PHP中更改实际图像,但如果仅在网页上需要,也可以在CSS中实现类似效果 这里有一个关于如何使用PHP和GD的完整教程:
使用CSS将是一个更容易的选择,使用
border
属性。您需要使用CSS来创建此效果。有几种选择
.img{
border-top:none;
border-left:none;
border-right:solid 2px #dddddd;
border-bottom:solid 2px #dddddd;
}
这是最简单的,但看起来不太好
为了制作更好的阴影,可以使用jQuery插件,比如阴影插件。它可以在页面上的任何元素上创建漂亮的阴影效果。如果这只是视觉效果,您可以尝试CSS3框阴影属性。不过,它只能在Firefox、Safari和Chrome上使用,所以它只是一个“渐进式增强”。应该有帮助 或者,您可以使用此CSS获得基本效果
gallery
是您为图像周围的元素指定的任何类名(即通过…
)。宽度/高度是可选的,但是如果图像大小都相同,那么最好使用CSS而不是图像本身的宽度/高度属性
.gallery img {
width: 100px;
height: 75px;
border-width: 0 3px 3px 0;
border-style: solid;
border-color: #ccc;
}
更好的解决方案:
function addBorderpng($add,$bdr=1,$color='#000000'){
$arr = explode('.', $add);
$extension = strtolower(end($arr));
$border=$bdr;
if($extension == 'jpg'){
$im=imagecreatefromjpeg($add);
}
else if($extension =='png'){
$im=imagecreatefrompng($add);
}
$width=imagesx($im);
$height=imagesy($im);
$img_adj_width=$width+(2*$border);
$img_adj_height=$height+(2*$border);
$newimage=imagecreatetruecolor($img_adj_width,$img_adj_height);
$color_gb_temp =HexToRGB($color);
$border_color = imagecolorallocate($newimage, $color_gb_temp['r'], $color_gb_temp['g'], $color_gb_temp['b']);
imagefilledrectangle($newimage,0,0,$img_adj_width,$img_adj_height,$border_color);
imagecopyresized($newimage,$im,$border,$border,0,0,$width,$height,$width,$height);
header('Content-type: image/jpeg');
if($extension == 'jpg')
imagejpeg($newimage,$add,9);
else if($extension == 'png')
imagepng($newimage,$add,9);
//imagepng($newimage);
//chmod("$add",0666);
}
function HexToRGB($hex){
$hex = ereg_replace("#", "", $hex);
$color = array();
if(strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
}
else if(strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}
addBorderpng('shahid.png',5);
函数addBorderpng($add,$bdr=1,$color='#000000'){
$arr=分解('.',$add);
$extension=strtolower(end$arr));
$border=$bdr;
如果($extension=='jpg'){
$im=imagecreatefromjpeg($add);
}
else if($extension=='png'){
$im=imagecreatefrompng($add);
}
$width=imagesx($im);
$height=imagesy($im);
$img_adj_width=$width+(2*$border);
$img_adj_height=$height+(2*$border);
$newimage=ImageCreateTureColor($img_调整_宽度,$img_调整_高度);
$color\u gb\u temp=HexToRGB($color);
$border\u color=imagecolorallocate($newimage、$color\u gb\u temp['r']、$color\u gb\u temp['g']、$color\u gb\u temp['b']);
imagefilledrectangle($newimage,0,0,$img_adj_width,$img_adj_height,$border_color);
imagecopyresized($newimage,$im,$border,$border,0,0,$width,$height,$width,$height);
标题(“内容类型:图像/jpeg”);
如果($extension=='jpg')
imagejpeg($newimage,$add,9);
else if($extension=='png')
imagepng($newimage,$add,9);
//imagepng($newimage);
//chmod(“$add”,0666);
}
函数HexToRGB($hex){
$hex=ereg#U替换(“#”)、“”、$hex);
$color=array();
如果(strlen($hex)==3){
$color['r']=hexdec(substr$hex,0,1)。$r;
$color['g']=hexdec(substr($hex,1,1)。$g);
$color['b']=hexdec(substr($hex,2,1)。$b);
}
else if(strlen($hex)==6){
$color['r']=hexdec(substr($hex,0,2));
$color['g']=hexdec(substr($hex,2,2));
$color['b']=hexdec(substr($hex,4,2));
}
返回$color;
}
addBorderpng('shahid.png',5);
通过php GD在图像周围添加边框
<?php
$img_src = '3.jpg';
$img = imagecreatefromjpeg($img_src);
$color = imagecolorallocate($img, 132, 15, 153);
$borderThickness = 10;
drawBorder($img, $color, $borderThickness);
function drawBorder(&$img, &$color, $thickness)
{
$x1 = 0;
$y1 = 0;
$x2 = imagesx($img) - 1;
$y2 = imagesy($img) - 1;
for($i = 0; $i < $thickness; $i++)
{
imagerectangle($img, $x1++, $y1++, $x2--, $y2--, $color);
}
}
header('Content-type: image/jpeg');
imagejpeg($img);
?>
并使用CSS将Borer添加到图像中
.border
{
width: 100px;
height: 75px;
border : 3px solid rgb(132, 15, 153);
}
<img src='3.jpg' class='border'>
.border
{
宽度:100px;
高度:75px;
边框:3倍实心rgb(132、15、153);
}
我如何让jquery工作,听到很多关于它的信息。。。这仅仅是指向某个库的那一步,还是还有更多?卡姆兰:这是第1步,共2步——你还必须告诉它该做什么。看,哦,当你的服务器内存不足时,我会大笑不已,同时将数百张图像转换为具有阴影的图像。我不确定你的意思。按照现代标准,这不会占用大量内存。如果这成为一个问题,则不需要实时处理图像,除非您为每个用户生成唯一的图像。只需生成一个带有阴影的图像,将其存储并引用即可。小心过早的优化,我们已经不是1998年了。
.border
{
width: 100px;
height: 75px;
border : 3px solid rgb(132, 15, 153);
}
<img src='3.jpg' class='border'>