Jump to content

Recommended Posts

i have a web site that uses jpeg images as backgrounds.

 

all works well exept that some images appear to big for the page,,, it cuts the top and sides off.

 

i dont want to stretch an image if not wide enough or not tall enough but,

what can i do to get the image to fit the page and not be to tall and wide.

 

this is the code that i have

 

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">';

if($img==null) {
   echo '<body link="#ffffff" vlink="#ffffff" alink="#ffffff">';
}else{
  echo '<body background="/home/'.$img.'" height="100%" link="#ffffff"  vlink="#ffffff"   alink="#ffffff">';
}

 

and my style sheet has this

 

body {
font-family: arial, helvetica, sans-serif;
color:#ffffff;
background-color:#00bfff;
background-attachment:fixed;
background-position:center center;
}

 

can anybody help....

thanks mike....

Link to comment
https://forums.phpfreaks.com/topic/154432-solved-background-images/
Share on other sites

i dont want to ask here but i dont want to start another thread,

 

is there away to resize these images when i upload them...

 

i use a php script to upload them.......

can i specify the height and have the width auto set to size of a jpg image on upload...

 

like if the image was width 1000px and height of 500px and i want to change the height to 1000px the width would auto change to 2000px when saving or change these values after saving.......

 

thanks mike....

First, yes, you can manipulate image sizes with the GD library as you upload them, but you also have to understand how background images work.  Your image is not going to stretch or shrink regardless of its container.  The image can only tile.  Therefore, it is pretty much impossible to have a photo fit exactly for each user, because different users will have different resolutions.  Tiling a photo will look very tacky, so you have to make some sort of design decision to fix your problem.

isnt there a way to use the <img> tag on the photo and set the height to 100% and let the width just be what it will be and then use a css wrapper to with a z-index of -1.

 

i can use this idea to get the image as a large image in the background and it works,

but how do i get that image to be fixed and center center...

 

i dont know that much about css wrappers.......

 

but i know that something like that is possible...

 

thanks mike..

i do not want to stetch the image....

 

i simply want to let the browser resize the image to fit the height of the page..

 

the width can fall out to what it may, to wide or to narrow or just right,,

 

like if i was to use <img src="some image" height="100%">...

but i want to put that behind my page and have it in the center and not scroll be attached.....

resizing the image like this

 

<?php
$img = $_GET['img'];

$src_img = imagecreatefromjpeg('../'.$img);
$srcsize = getimagesize('../'.$img);

$dest_y = 800;
$dest_x = (800 / $srcsize[1]) * $srcsize[0];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);		

imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 
	$dest_x, $dest_y, $srcsize[0], $srcsize[1]);

header("content-type: image/jpeg");
imagejpeg($dst_img);

imagedestroy($src_img);
imagedestroy($dst_img);
?>

 

then calling this script as my background image like this...

 

<body background="location of resize file ?img='image to resize' "  link="#ffffff" vlink="#ffffff" alink="#ffffff">

 

works great, just change the size value and you can properly adjust the size of an image

 

it can be modified to work with other image types as well

 

source = /www.earn-web-cash.com/2008/01/30/resize-images-php/

 

thanks mike...

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.