1

Just like html pages are coded in a text editor and saved as .html, can we do the same thing by coding a .jpg file? How are jpg files coded and built?

  • 2
    JPEG is not an image description language, it's a compression method. If I understand correctly, you want to 'describe' an image (say, by specifying circles and rectangles with position, size, and color) and save *that* as a JPEG. (But, typically JPEG is used for photos and photo-like images.) – Jongware Oct 19 '13 at 09:47
  • could you tell me which language is used for image description? –  Oct 19 '13 at 10:09

1 Answers1

2

As Jongware already said in his comment, JPEG is a compression method. Just open a JPEG file in a text editor, and you will see that it doesn't look like something that can be created by hand at all.

If you want to "code" an image, you can't use a bitmap image format like JPEG - you need a vector image format (see this for an explanation about the difference).

There are probably more, but the first one that comes to my mind is SVG (Wikipedia article about SVG).

You "code" SVG files in XML, and all modern browsers are able to render it.

Here is an example, copied from the German version of the Wikipedia article above:
(the English article didn't have a linkable rendered example file, just the source code. So I took the example from the German article and just translated the comment)

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
        version="1.1" baseProfile="full"
        width="700px" height="400px" viewBox="0 0 700 400">

        <!-- connectors left and right -->
        <line x1="0" y1="200" x2="700" y2="200" stroke="black" stroke-width="20px"/>
        <!-- the rectangle -->
        <rect x="100" y="100" width="500" height="200" fill="white" stroke="black" stroke-width="20px"/>
        <!-- the arrow line -->
        <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px"/>
        <!-- the tip of the arrow -->
        <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)"/>
</svg>

The rendered image looks like this:
http://en.wikipedia.org/wiki/File:Variable_Resistor.svg

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
  • 1
    Yes, SVG is probably the best way to "write" an image by hand these days. While you can't create JPEGs by hand (well, not unless you're a *really* scary person), you may also want to look into libraries/programs like [ImageMagick](http://www.imagemagick.org/script/index.php), or [GD](http://en.wikipedia.org/wiki/GD_Graphics_Library) that will allow you to "build" raster images through scripting with commands that let you "draw line", "draw circle", etc. and export the results in JPEG format. – Matt Gibson Oct 19 '13 at 10:37
  • Nice. It answered my question. To convert the svg image to bitmap/jpeg is there an algorithm? or another programming language? –  Oct 19 '13 at 10:57
  • Concerning conversion, see [this question](http://stackoverflow.com/questions/1019462/how-to-convert-svg-files-to-other-image-formats) and [this question](http://stackoverflow.com/questions/1861382/convert-png-to-svg) *(for example)*. If my answer solved your problem, please consider [accepting](http://stackoverflow.com/help/someone-answers) it. – Christian Specht Oct 19 '13 at 11:01
  • Christian Specht I liked the answer. It answered my question really well. But i need minimum 15 reputation to answer it –  Oct 19 '13 at 11:06