micmania1 Posted May 23, 2008 Share Posted May 23, 2008 Is there away I can specifiy an images height and width as well as using an existing image as its background? I can only seem to do 1 of them. Link to comment https://forums.phpfreaks.com/topic/106942-php-image-height-width-background-image/ Share on other sites More sharing options...
947740 Posted May 23, 2008 Share Posted May 23, 2008 Yes. $location needs to be the location of the image relative to the current directory. If you want to display an image on a webpage: echo "<img src='$location' height='235' width='236' />"; Background image on a page: echo <<<END <style type='text/css'> body { background-image: url($location); } </style> END; Link to comment https://forums.phpfreaks.com/topic/106942-php-image-height-width-background-image/#findComment-548178 Share on other sites More sharing options...
micmania1 Posted May 23, 2008 Author Share Posted May 23, 2008 Sorry, I wasn't spcfic enough. Im generating an image using php (GD libraries), but the height it dependant on the amount of records it needs to show, which is pulled from the db. <?php require_once "admin/mysql_connect.php"; // Image sizes $header_height = 40; $footer_height = 16; $row_height = 16; $image_width = 250; // Combination of header and footer height $image_constants_height = $header_height + $footer_height; // Image Settings $font_size = 12; $title_size = 17; $title_font = 'fonts/ARAR.ttf'; $font_file = 'fonts/amazr.ttf'; if (is_numeric($_GET['league_id'])) { $query = "MY_QUERY..."; $result = mysql_query($query); if ($result) { $num_users = mysql_num_rows($result); if ($num_users > 0) { // Image height including num_users and image constants $image_height = ($num_users * $row_height) + $image_constants_height; header("Content-type: image/jpeg"); /* I WANT THIS AS A BACKGROUND IMAGE ---------------------- $image = imagecreatefromjpeg('images/football_pitch.jpg'); ----------------------------------------------------------------*/ $image = imagecreate($image_width, $image_height); $bgcolor = imagecolorallocate($image, 0, 130, 0); $font_color = imagecolorallocate($image, 255, 255, 255); if ($image) { // Font settings @imagettftext($image, $title_size, 0, 5, 23, $font_color, $title_font, 'DOMAIN.com'); @imagettftext($image, $font_size, 0, 72, 38, $font_color, $title_font, 'Site description'); } else { echo 'error'; exit(); } } } } imagejpeg($image); imagedestroy($image); ?> Thescript isn't finished yet. I'm just getting the basics sorted first. Link to comment https://forums.phpfreaks.com/topic/106942-php-image-height-width-background-image/#findComment-548197 Share on other sites More sharing options...
947740 Posted May 23, 2008 Share Posted May 23, 2008 Oh. I am no help then, because I know nothing about generating images. Sorry. Link to comment https://forums.phpfreaks.com/topic/106942-php-image-height-width-background-image/#findComment-548201 Share on other sites More sharing options...
micmania1 Posted May 23, 2008 Author Share Posted May 23, 2008 ^ Link to comment https://forums.phpfreaks.com/topic/106942-php-image-height-width-background-image/#findComment-548421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.