Welcome Guest, Not a member yet? Register   Sign In
Automatic Background Resize
#1

[eluser]DocFunky![/eluser]
Hello World !

I would like the background to get automatically adapted to the screen resolution.

So, here is what I did, but I get an erro message, let me show you :

First I wanna get the User Screen through a Cookie (I definitively don't want it to get by the GET method) :

Code:
<?php
if(isset($_COOKIE["users_w"])){

$screen_w = $_COOKIE["users_w"];
$screen_h = $_COOKIE["users_h"];

}else //means cookie is not found set it using Javascript
{
?>
[removed]
writeCookie();
// Ma première fonction Javascript !
function writeCookie(){

var today = new Date(); // On rentre d'abord la date de création du cookie
the_date.setTime(the_date.getTime()+60000); // On rentre ensuite la date de péremption du cookie
    

var the_cookie_date = the_date.toGMTString(); // On l'adapte à GMT ?
var the_cookie1 = "users_w="+ screen.width; //On enregistre le width dans cookie1
var the_cookie2 = "users_h="+ screen.height; //On enregistre le height dans cookie2
var the_cookie1 = the_cookie1 + ";expires=" + the_cookie_date; // ON rajoute les dates de peremption
var the_cookie2 = the_cookie2 + ";expires=" + the_cookie_date;

//commandes pour enregistrer le cookie chez l'utilisateur dans un petit tableau
[removed]=the_cookie1
[removed]=the_cookie2

// Et on dit ou il va
location = '<?php base_url();?>';

}
</script>
<?php
}
echo "Your screen resolution is set at ". $screen_w."xxx".$screen_h; // Just to be sure
?>

Forget about the French comments, useless Smile

Then, I get my pic and load the librairy I found there :

Librairy : http://ellislab.com/forums/viewthread/178095/

Then I get my image in a variable
Code:
$Pic="Paris.jpg";

That I want to give to the function right after, so I get :

Code:
<?php
//Dans cette partie nous nous occupons de la selection du fond d'écran selon la ville et l'heure

$Pic="Paris";

$this->load->library('Images');

$this->images->resize(base_url().assets/images/background/.$Pic.".jpg" , base_url().assets/images/background/.$Pic."Resized.jpg" , $width, $height);  

?>

So considering the Directions for the Image Manip librairy, we should have something la this :
Code:
$this->images->resize('full_path on image', 'path of new image', '120','90'));

All this code is here in order to get a resized image background so that right after this code I have
Code:
<body background=" <?php echo base_url();?>assets/images/background/<?php $Pic ?>Resized.jpg" >

And you will find this code in the header of my website.
Just before the logo get printed.

That what I think I did ... I'm not sure about the images paths, does base_url().assets/images/background/.$Pic.".jpg" work ?
Well definitively not, I don't know how to do something like this.
So I tried first with static paths like assets/images/background/Paris.jpg for each of the url (No need to rewrite it here .. well let's do it :

Code:
$Pic="Paris";

$this->load->library('Images');

$this->images->resize(localhost/codeIgniter/assets/images/background/Paris.jpg , localhost/codeIgniter/assets/images/background/ParisResized.jpg , $width, $height);  

?>
  
<body background=" localhost/codeIgniter/assets/images/background/ParisResized.jpg" >

)

So now here is me problem :


Here is my error message I get when I try :
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$images

Filename: template/header.php

Line Number: 109

Fatal error: Call to a member function resize() on a non-object in D:\Programmes\wamp\www\codeIgniter\application\views\template\header..php on line 109


So line 109 is this one :
Code:
$this->images->resize(localhost/codeIgniter/assets/images/background/Paris.jpg , localhost/codeIgniter/assets/images/background/ParisResized.jpg , $width, $height);

Why isn't it considered as an object ?




Theme © iAndrew 2016 - Forum software by © MyBB