fife Posted January 22, 2013 Share Posted January 22, 2013 (edited) Im trying to echo the width and height of an image into a looping array I have. Everything other than the width and height seems to be there. The images are displayed in a carousel that I have. For the carousel to work properly it likes to have the image width and height. I dont want to enter manual values and distort the images!! Here is a snippet of my code. <?php do { $image = $row_rs_imgpath['userimagespath'].$row_rs_smimg['thumbfile']; $x= imagesx($image); $y = imagesy($image); ?> <img src="<?php echo $image; ?>" alt="<?php echo $row_rs_smimg['imgname']; ?>" width="<?php echo $x;?>" height="<?php echo $y;?>" /> <?php } while ($row_rs_smimg = mysql_fetch_assoc($rs_smimg)); ?> And when you view the page source code you get the following: <img src="/images/uploads/my-future-car-1358783315_thumb.jpg"width="" height="" /> <img src="/images/uploads/albert_docks_liverpool-1358872736_thumb.jpg" width="" height="" /> I have also tried list($width, $height)= getimagesize($image); but that doesnt work either. Edited January 22, 2013 by fife Quote Link to comment https://forums.phpfreaks.com/topic/273498-show-my-image-width-and-height/ Share on other sites More sharing options...
.josh Posted January 22, 2013 Share Posted January 22, 2013 read the manual entry for imagesx and imagesy. It requires an image resource, not some arbitrary filename (string). Quote Link to comment https://forums.phpfreaks.com/topic/273498-show-my-image-width-and-height/#findComment-1407540 Share on other sites More sharing options...
.josh Posted January 22, 2013 Share Posted January 22, 2013 I think perhaps you may want to try using getimagesize instead. Quote Link to comment https://forums.phpfreaks.com/topic/273498-show-my-image-width-and-height/#findComment-1407541 Share on other sites More sharing options...
fife Posted January 22, 2013 Author Share Posted January 22, 2013 Thanks Josh. Its been solved. I needed to use $_SERVER['DOCUMENT_ROOT'] $image = $_SERVER['DOCUMENT_ROOT'].$row_rs_imgpath['userimagespath'].$row_rs_smimg['thumbfile']; Quote Link to comment https://forums.phpfreaks.com/topic/273498-show-my-image-width-and-height/#findComment-1407543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.