Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you dynamically put different patterns on images in a webpage .

i have

  1. A bunch of fabric patterns (simple jpg files)
  2. An image for every letter of the alphabet(blank white background)

I essentially want to have a page similar to this: http://www.craftcuts.com/hand-painted-wooden-letters-single-patterns.html

but instead of having it as a static page, i would like a user to be able to:

  1. Type in a name
  2. Choose a pattern (one of the jpg files)

and then have it display that name in that pattern.

Obviously i could create separate jpgs for every combination of letters (right now i have a jpg for every letter with white back color) and patterns but i wanted to find out if there was a more elegant way of coding this up to have it dynamically put one image onto the letter in the other.


EDIT: In my initial post, i assumed that this would have to be a front end thing (javascript), but if it makes it any easier (as a few people asked what is the backend), my back end is an asp.net-mvc so if there is some solution to build this up on the serverside and ship down to the client, i am more than happy using that as well.

like image 552
leora Avatar asked Nov 04 '09 06:11

leora


People also ask

How do I create a dynamic image in HTML?

To include a dynamic image in an HTML campaign document, use a $fieldName$ text replacement field in the img tag, where the fieldName column in the distribution list or a supplemental data source contains image URLs), the value in the specified field must not include the protocol ( http:// ).

Which element should we use to put images on a Web page?

How do we put an image on a webpage? In order to put a simple image on a web page, we use the <img> element. This is a void element (meaning, it cannot have any child content and cannot have an end tag) that requires two attributes to be useful: src and alt .


2 Answers

You can apply background images to images using CSS, then use a load of transparent .png images for the letters.

I mocked it up:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>

<style type="text/css">

 img.leaves
 {
    background:url("leaves.png");
 }
 img.lights
 {
    background:url("lights.png");
 }

</style>

<script type="text/javascript">

function makeText()
{
    var text = document.getElementById('text').value.toUpperCase();
    var pattern = document.getElementById('pattern').value;

    for(var i=0; i<text.length; i++)
    {
        var img = document.createElement('img');
        img.src=text[i]+'.png';
        img.className=pattern;
        document.getElementById('textArea').appendChild(img);
    }

    return false;
}

</script>

</head>

<body>

<form onsubmit="return makeText();">
<p><label for="text">Enter your text</label> <input type="text" name="text" id="text" size="20"></p>
<p><label for="pattern">Choose a pattern</label> <select id="pattern"><option value="leaves">Leaves</option><option value="lights">Lights</option></select></p>
<p><input type="submit" value="Make!"></p>
</form>

<div id="textArea"></div>

</body>
</html>

and you can also see it in action.

alt text http://www.subdimension.co.uk/files/1/SO/A.png < this is one of the letter cutouts (difficult to see!)

alt text http://www.subdimension.co.uk/files/1/SO/leaves.png and one of the background patterns.

I got bored at G, so you can only write words that contain the letters a-g, it's also a little lazy in that it only does upper case and there are only 2 patterns but hopefully it should be enough to give you an idea

like image 86
MalphasWats Avatar answered Oct 14 '22 12:10

MalphasWats


You could use the ImageMagick libraries to make any combination of superimpositions your and your users' hearts desire. This way, you're not limited to just something simple that can be achieved with CSS.

ImageMagick examples

like image 11
Artem Russakovskii Avatar answered Oct 14 '22 10:10

Artem Russakovskii