Search This Blog

Wednesday, July 22, 2009

Php Code in Dynamic < img > tag - 22nd July

For all Web Designers, I'm sure there are times when there is a need to code in Php into < img > tags such as when the image source is dynamic or the image size is dynamic. Therefore, this is how you do it: simply by using the < ?= x ? > tag!

Example:- You want an image to achieve a particular length / width. Therefore, the basic procedure would be to write the equation / code as php first, defining the relevant parameters. In this case, say the parameter is $img_height. Then the code for the image tag would be < img src="http://....x...." width="< ?= $img_height = >" > and that's it, you've got yourselves php code in the img tag! Of course, in this case the best way would be to either floor() or ciel() the value as the width cannot be in fractions. Screens cannot display a fraction of a pixel mind you.

No comments: