EZE Posted January 22, 2007 Share Posted January 22, 2007 How what function do i use to create a solid 1px black border around a pre-existing image? I researched GD library, and nothing really made sense. Can someone help please? ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/ Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 wont CSS do?border:1px solid #000 Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166760 Share on other sites More sharing options...
The Little Guy Posted January 22, 2007 Share Posted January 22, 2007 just use CSS, unless you want the border to be apart of the image.then[code]// Create border around imageimageline($image, 0, 0, 0, $imgHeight, $colorGrey);imageline($image, 0, 0, $imgWidth, 0, $colorGrey);imageline($image, $imgWidth-1, 0, $imgWidth-1, $imgHeight-1, $colorGrey);imageline($image, 0, $imgHeight-1, $imgWidth-1, $imgHeight-1, $colorGrey);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166762 Share on other sites More sharing options...
Nolongerused3921 Posted January 22, 2007 Share Posted January 22, 2007 If you mean to the actual image itself, try http://www.php.net/manual/en/function.imagerectangle.php or make the image a few pixels bigger, use http://www.php.net/manual/en/function.imagefill.php, then import the picture and offset it a pixel or two. Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166764 Share on other sites More sharing options...
EZE Posted January 22, 2007 Author Share Posted January 22, 2007 Okay, I tried [code]<? imagerectangle(image.png, 0, 0, 149, 171, #000000);?>[/code], but it said this: [quote]Parse error: parse error, unexpected ';' in /home/content/e/z/e/ezevolk/html/tests/image_functions/index.php on line 3[/quote] What did I do wrong? Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166776 Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 image.png needs to be a string, surrounded with '''image.png' Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166777 Share on other sites More sharing options...
EZE Posted January 22, 2007 Author Share Posted January 22, 2007 I did that, and the same error comes up. Do I have to add single quotes around the color too? Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166778 Share on other sites More sharing options...
The Little Guy Posted January 22, 2007 Share Posted January 22, 2007 yes, because the pound sign isn't a number Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166781 Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Yeah. Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166782 Share on other sites More sharing options...
EZE Posted January 22, 2007 Author Share Posted January 22, 2007 Now it says this [quote]Warning: imagerectangle(): supplied argument is not a valid Image resource in /home/content/e/z/e/ezevolk/html/tests/image_functions/index.php on line 2[/quote](Also, thank you for helping me with this!) Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166783 Share on other sites More sharing options...
ShogunWarrior Posted January 22, 2007 Share Posted January 22, 2007 You don't give the image functions the filename, you give them a file handle. E.g:[code]$im = imagecreatefrompng( 'image.png' );$black = imagecolorallocate($im,0,0,0);imagerectangle($im, 0, 0, 149, 171, $black);//WARNING, THIS WILL OVERWRITE THE ORIGINAL!!imagepng($im,'image.png');[/code]The above code should create the border and overwrite the old file with the new image. Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166785 Share on other sites More sharing options...
EZE Posted January 23, 2007 Author Share Posted January 23, 2007 Cool! That worked! Now, if my image is 149 by 171, should i set the finishing x and y positions to be that? Because I did, and the image's border cut off in the bottom and right sides of the image, they didn't show up at all. Do I have to subtract 1 from each finishing coordinate? Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166824 Share on other sites More sharing options...
ShogunWarrior Posted January 23, 2007 Share Posted January 23, 2007 Yep, subtract 1 from the width and height. Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166843 Share on other sites More sharing options...
EZE Posted January 23, 2007 Author Share Posted January 23, 2007 Okay, thank you. What if I wanted to expand the image by 1px on all sides, leaving blank pixels, not stretching out the image, then applying the border. For example, i have a 50 by 50 image, and i draw a 1 px border all the way around it, and the border expands the image size, but the image stays the same. Pretty much like adding a css border. Quote Link to comment https://forums.phpfreaks.com/topic/35281-image-border-create/#findComment-166856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.