Jump to content

Dynamic image height


John H

Recommended Posts

What I am working on is a background to a user input comment -- essentially a framed box around the comment. For some reason I cannot fathom but which is probably simple, I can't get the image height variable, (set by the length of the comment) to be seen by the code outputting the framed box. So here's what I got:

 

To set the image position and height variables I put this code inside of a while loop, since there are multiple comments in the DB:

 


//Looks at the comment in the DB
//Calculates the number of lines based on 75 characters per line
$line_count = ceil(strlen($row3['comment'] /75));

//This sets the position of the username who posted the comment
$username_pos = ($text_pos + ($line_count * 33)) . ".00pt";	

//Sets the initial starting position of the framed box on the page
$box_pos = $text_pos - 42.00 . ".00pt";

//Sets the height of the framed box 
$box_ht = $username_pos + 50 . ".00pt";

//Outputs the framed box 
echo "<img src='images/blue table.gif' style='position:absolute; left:140.00pt; top:$box_pos'; height:$box_ht'; width = 570.00pt; z-index:-1 class='cc01'>";

 

There is also code outputting the comment and username which seems to work just fine.

 

The result is a pretty box framing the comment, but the outputted image always ends up with the same height, which obviously doesn't work because each comment in the DB can have a different number of lines and would need a different size box.

 

Just to be clear, the source image is much larger than what can be produced by this code.

 

If anyone has any suggestions, I'd really appreciate it. Thanks!

Link to comment
Share on other sites

Thanks for writing. The reason I didn't do this with CSS is because you can't use variables with CSS. It is my understanding that they are considering allowing variables in future versions, but as far as I know, that hasn't happened yet.

 

The reason I need to use a variable is because the height of the image -- essentially a box that frames the comment--would be defined by the length of the comment. Any given comment a user submits could output as 1,2,3 lines (or more) on the web page, depending on the length of the comment. So, the box image height has to be a variable based on the comment length.

 

Does that make any sense?

Link to comment
Share on other sites

yes.. so why not have 3 images.. top image.. middle image.. bottom image (assuming all the comments are the same width..)

 

then all you do is something like this :)

 

<div class="comment">

  <div class="comment-top"> </div>

  <div class="comment-middle">

    comment goes here! :)

  </div>

  <div class="comment-bottom"> </div>

</div>

 

and give the images accordingly to the divs :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.