Reputation: 14281
I want to add text onto an image giving the text a transparent black background. Essentially, I want to achieve the effect described in the following link:
The problem is that I am dynamically generating these images and randomly placing them on the screen. Therefore, I cannot absolutely position the text (at least, not without knowing the height of the text in total). Is there another way to do this?
Thanks!
Upvotes: 0
Views: 9396
Reputation: 98926
I am dynamically generating these images and randomly placing them on the screen.
Without seeing some of the code you have so far, it’s a bit difficult to help. If you’re dynamically generating the images, couldn’t you also dynamically generate the text along with it?
I.e. instead of generating:
<img style="position: absolute; top: RANDOMVALUE; left: RANDOMVALUE;">
Could you generate:
<div class="image-with-text-over-it" style="position: absolute; top: RANDOMVALUE; left: RANDOMVALUE;">
<img>
<p>Text to be overlaid on image</p>
</div>
And then in your stylesheet, write some CSS that positions the text in every instance of this over the image in that instance:
.image-with-text-over-it p {
position: absolute;
bottom: 2em;
left: 0;
color: #fff;
background: rba(0, 0, 0, 0.8);
}
Upvotes: 0
Reputation: 4977
you can position text absolutely. once images are loaded, even if randomly, jQuery's position() method will provide you will all the information you need.
obviously, you would like to to encapsulate images in containers e.g. or use and set image using div's background image. then you have all the freedom to put whatever text/effects you want in the container.
Upvotes: 1