Jump to content

PHP image (height, width & background image)


micmania1

Recommended Posts

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;

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.