Page 1 of 1

Automatically resize image upon its conversion from text

Posted: Thu May 27, 2010 5:05 am
by linu
I want to convert a text retrieved from database and need to convert it into image.And The Image need to be automatically resized according to the data in the database,, Is It Possible? :(

Re: Automatically resize image upon its conversion from text

Posted: Thu May 27, 2010 12:00 pm
by hypedupdawg
Sorry - I don't quite understand. Are you saying that you have text in a database which then links to an image, or that you want to convert the actual text into an image?

Either way, resizing an image is easy. You can simply pass the database query into a variable, then echo it further down:

Code: Select all

<img src="<?php echo $imgSrc; ?>" width="<?php echo $imgW; ?>" height="<?php echo $imgH; ?>" />
To make sure you don't stretch and distort any images, I reccomend that you store the ratio and one dimension of the image in the database Assuming you store the ratio 4:3 and the width of the image, you can do something like this:

Code: Select all

<?php
$imgRatio = explode(":",$imgRatio);
$imgH = floor(($imgW / $imgRatio[0]) * $imgRatio[1]);
?>
Remember to floor() your results, as HTML really does not like decimal numbers!