Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a Preview image by stacking transparent images based on Form selections using JavaScript?

Tags:

People also ask

How do you preview an image before it is uploaded using jquery?

First, we have a division element that contains the “img” tag. Using Jquery, we will change the “src” attribute of the “img” tag on upload to preview the image. The second element is the “input” tag. It is essential to specify type = “file” in this context.

How do I display an image before uploading HTML?

The most efficient way would be to use URL. createObjectURL() on the File from your <input>. Pass this URL to img. src to tell the browser to load the provided image.


Using HTML, CSS, and JavaScript I need to build a Form with Selection input fields and Radio selection fields. When each one of these fields is selected, I need to build a Preview image based on the selection they made.

Each field will have an Image associated with it and then it will also have that same image replicated for each color.

So if there was 20 Form fields that a user could pick it would have 20 images x 10 different color options and would result in there being 200 possible images to build there preview image!

Here is an image that shows an example of what I am trying to accomplish...the Vans website uses this technique for a custom shoe generator with preview... http://i.stack.imgur.com/O61hQ.png

When you pick a section and then the color for that section, it loads a transparent image and stacks them together.

For testing, I have made a set of transparent images for a demo form with only 4 Fields and 3 color choices so 12 images in total. (All shown below)

When all the fields have been selected it should build an image preview to the user that is similar to this...
http://i.imgur.com/JYJdBnN.png

or the Alternative has a Top/Roof more like an octagon type shape

enter image description here


bottom_blue
http://i.imgur.com/fsG49zS.png


bottom_green
http://i.imgur.com/TdjBCXk.png


bottom_red
http://i.imgur.com/UxCyzij.png


entrance_blue
http://i.imgur.com/yLPtqYF.png


entrance_green
http://i.imgur.com/YoxBjxL.png


entrance_red
http://i.imgur.com/LQ07PgU.png


top_blue
http://i.imgur.com/2ZmjBYe.png


top_green
http://i.imgur.com/kImYjxF.png


top_red
http://i.imgur.com/wgtFL6h.png


top_red_octo enter image description here


top_blue_octo enter image description here


top_green_octo enter image description here


Here is a basic form that could use the images...

http://jsfiddle.net/Pha4V/

<form id="form-ChannelType">   <p>         Select a bottom (just 1 in the demo)<br>         <select name="bottom" class="form-control" id="bottom" size="1">           <option value="bottom1">Bottom 1</option>         </select>   </p>   <p>         Select a Front (just 1 in the demo)<br>         <select name="front" class="form-control" id="front-1" size="1">           <option value="front1">Front 1</option>         </select>   </p>     <p>         Select a Top<br>         <select name="bottom" class="form-control" id="bottom" size="2">           <option value="bottom_triangle">Triangle Shaped Top</option>           <option value="bottom_octo">Octo. Shaped Top</option>         </select>   </p>        <p>         Select a Color<br>         <select name="color" class="form-control" id="color" size="3">           <option value="blue">Blue</option>           <option value="green">Green</option>           <option value="red">Red</option>         </select>   </p> </form> 

Can anyone help me in the logic of how to make such a form work? I need to make it work in a way that can easily scale to hundreds of options and images.

With the basic form above, it would need to build a preview image by stacking appropriate images based on the form selections. I don't expect anyone to do all the work for this unless they are simply up for the challenge but I would appreciate any help or ideas on how to best make this work?


NOTE: My final project that will be based off of this will be much different. It will be used for a custom sign generator. I cannot use ImageMagick or GD libraries to do on the fly images, so each image has to be built and each layer changed. Instead of abuilding a simple house structure I will have options such as...

  • Sign Type which will determine a lot of the setting that are shown or hidden after it based on the type of sign selected.
  • Font the base image will have one for each font and in each font will be in each color as well. So 10 fonts x 15 colors = could easily be over 150 possible images to show just as the BASE image
  • Colors There will be from 2-4 different color options that will change the color for different parts of the sign. So all the image combinations listed above x the different color areas = lots of images

So you can see this will be a pretty big beast when it's all done and I could use any help in getting a good start on it. I don't think a HUGE if/else or switch statement is the best way to go with something like this that can have hundreds of image combinations but I could be wrong?