views:

28

answers:

3

I want to improve one of my Facebook apps by allowing the users to apply border styles to their images. I am not exactly sure how this can be done, but hopefully someone here will be able to help. The application is written in PHP. I originally thought that I would be able to create an image with just the border, a few pixels wider and taller than the image I wanted to add the border to, then just merge the two images, but that didn't work.

Any help would be great, and rewarded with your name and Stackoverflow profile image postedon the Credits page of the app.

+2  A: 

Try putting the background image in the CSS background property.

How about some code using random images from google searches?

<div id="myWrapper" >
  <img src="http://www.iconarchive.com/icons/rokey/the-blacy/128/secret-smile-icon.png" id="myImage" />
</div>
<style>
    #myWrapper {
    background-image: url(http://images.clipartof.com/small/210747-Royalty-Free-RF-Clipart-Illustration-Of-A-Diamond-Plate-Border-Frame-Around-Blank-White-Space.jpg);
    width: 450px;
    height: 450px;
}

#myImage {
    margin: 160px 160px;
}
</style>

Note: I don't claim these images. I'm just saying this cos somebody's gonna bitch. Watch and see ;)


EDIT

I see now however that maybe he does just want to add a style as another poster suggested. So now we're back to asking the OP does he mean how does he store user preferences for images and then dynamically add that style onto an image as it's posted from the app?

I guess that would call for an inline style wouldn't it? ;)

myImageSource = "<img src='".imgSrc."' style='border: 2px solid ".imgBorderColor.";'/>";
drachenstern
Thanks, @drachenstern! This is exactly what I needed for the solid borders. Now, how about adding styled borders (i.e. clouds, sky or stars ) to the images?
Zachary Brown
You either use an image for the backgroundedness as I demonstrated or you could have several images, one for each border. This gets off way into fuzzy CSS stuff, so you have to be a lot lot lot more explicit on what you want. Like, make us a mockup in Paint.NET (meaning, do it right, take your time, give us a good idea what you want) and then ask a new question. I can imagine two or three ideas for what you're asking, it all just depends.
drachenstern
I remembered the link! You want to start here: http://www.infimum.dk/HTML/slantinfo.html ... one border for each side of the image (red, green, yellow, blue) ...
drachenstern
I need the user to be able to choose a "frame", then the app placing the frame around the image. Now, I the user should still be able to save the image ( and the frame ) after it has been added. I already have one put together here: http://zbrowntechnology.info/ImgDisp/imgdisp.php
Zachary Brown
Then you're going to have to either do what @PureForm suggested below and allow them to save it or you're going to have to do what I showed above which allows for a freeform border and image.
drachenstern
I attempted to use yours, but couldn't get the image to lay on top of the border image. I also wasn't able to save the image with the border, just the image.
Zachary Brown
Yes. Mine is purely a display trick. You want to do something (apparently) on the server. Mine only works in the browser. Did you copy and paste my code into your test page? It's strictly clientside so shouldn't need any adjustments. Try it before editing it.
drachenstern
I did try it before editing it, and it worked great. But I need something that the user can save. I was looking into PHP GD's imagecopymerge() method, but couldn't figure it out. Wen I tried that, only the background image was displayed. Know anything about that?
Zachary Brown
I don't do PHP, so no. But I bet if you start a new question (so it has a clean slate feel to it) and post asking specifics on that question with the code you've got that doesn't work, I bet you can get a good answer on that topic. Wish I could help more with that.
drachenstern
Yeah, my trick is only for display. It uses CSS and screen layering. It's still two different elements tho.
drachenstern
@Zachary Brown ~ Last bit of advice before I go home. On that other question, tag it as PHP, add the bits of code you attempted on the GD ImageRectangle and mention that you're looking to do something serverside. Otherwise you'll end up getting the same answers as you go there. Not Very Helpful, to be sure.
drachenstern
+1  A: 

Assuming you're using GD to create the images, you can use imagerectangle() to put a border around the image. PHP.net has a great example: http://us2.php.net/manual/en/function.imagerectangle.php

PureForm
A: 

@drachenstern: CSS is a good idea, but how would the background help? CSS has a border property that can be used. ;) img.someclass { border: 2px solid black; }

Savageman
Because he wants to make a style based change to his existing elements. ~ Or alternately, because maybe I'm reading the question wrong and you're reading it correctly?
drachenstern