meomike2000 Posted April 17, 2009 Share Posted April 17, 2009 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.... Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/ Share on other sites More sharing options...
meomike2000 Posted April 17, 2009 Author Share Posted April 17, 2009 in case you dont understand what i am trying to say happens, it is as if the photo is being zoomed in on..... it only shows a small section of the center of the photo. and it dont do it on all photos...... Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812006 Share on other sites More sharing options...
meomike2000 Posted April 17, 2009 Author Share Posted April 17, 2009 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.... Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812065 Share on other sites More sharing options...
jcombs_31 Posted April 17, 2009 Share Posted April 17, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812220 Share on other sites More sharing options...
meomike2000 Posted April 17, 2009 Author Share Posted April 17, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812529 Share on other sites More sharing options...
jcombs_31 Posted April 17, 2009 Share Posted April 17, 2009 I can't imagine why you would want to stretch an image, it is going to look like crap. Raster graphics are not designed to expand. Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812595 Share on other sites More sharing options...
meomike2000 Posted April 17, 2009 Author Share Posted April 17, 2009 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..... Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812597 Share on other sites More sharing options...
meomike2000 Posted April 18, 2009 Author Share Posted April 18, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/154432-solved-background-images/#findComment-812865 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.