Jump to content

DeanWhitehouse

Members
  • Posts

    2,527
  • Joined

  • Last visited

Everything posted by DeanWhitehouse

  1. Try <?php $src_image = imagecreatefromjpeg($stored_image); $new_thumb_width = 85; $new_thumb_height = 64; list($width, $height) = getimagesize($src); $thumb_w = $new_thumb_width; $thumb_h = $new_thumb_height; $thumb = imagecreatetruecolor($thumb_w, $thumb_h); imagecopyresampled($thumb, $src_image,0,0,0,0,$thumb_w, $thumb_h, $width, $height); imagejpeg($thumb); imagedestroy($src_image); imagedestroy($thumb); echo $thumb_w; echo "<br/>"; echo $thumb_h; ?>
  2. Not with PHP alone, try looking at ajax, or maybe a css based alternative
  3. Ok still got the problem, but here is a working version using OOP <?php /** *Page to show a different avatar each time * * *@package Avatar Randomness *@author Dean Whitehouse (aka Blade280891) - deanwhitehouse6@hotmail.com - http://www.djw-designs.com - http://www.djw-webdesign.awardspace.com */ session_start(); /* Begin sessions, for more info visit either: The php manual, http://uk.php.net/session or my sites tutorial on using sessions to protect pages, http://djw-webdesign.awardspace.com/code.php?snippet=9 */ class Avatar { public $avatar_resize = 150;//The amount , in percent, to resize the avatar /* Uncomment these lines to change the image using set widths and heights, only un comment one to keep the image aspect ratio public $new_width = 128;//In pixels public $new_height = 264;//In pixels */ public $avatars = array ( "http://spearbang.awardspace.com/Sonic-animated.gif", "http://spearbang.awardspace.com/Tails-salutes.gif", "http://spearbang.awardspace.com/Sonic-and-Shadow-transform.gif", "http://spearbang.awardspace.com/Knuckles2.gif" ); /* Store the avatars in an array, for more info on arrays visit; The php manual, http://uk3.php.net/array or my site, http://djw-webdesign.awardspace.com/code.php?snippet=8 */ public $avatar_count; function __construct() { $this->avatar_count = count($this->avatars) - 1; if(isset($_SESSION['random']))// check for the session that contains the random number then unset it. { unset($_SESSION['random']); /* Unset the session that stores the random image reference number, for more info; The php manual, http://uk.php.net/unset */ } $_SESSION['random'] = mt_rand(0, $this->avatar_count); /* Generate a new number for the image reference number */ if(!isset($_SESSION['num'])) { $_SESSION['num'] = $_SESSION['random']; } } /** *Function to generate the avatar image. * *Selects an image, resizes the image and then sends the image and headers to the browser *@return string image */ function Generate_Image() { return self::Resize_Image($this->avatars[$_SESSION['random']]); } /** *Function to resize the image. * *Resizes the inputted image *@param string image url *@return string new image url */ function Resize_Image($image) { $current_image = $image; $image_type = self::Get_Image_Type($current_image); //http://uk.php.net/switch switch($image_type) { case "jpg": $new_image = imagecreatefromjpeg($current_image); break; case "jpeg": $new_image = imagecreatefromjpeg($current_image); break; case "gif": $new_image = imagecreatefromgif($current_image); break; case "png": $new_image = imagecreatefrompng($current_image); break; case "bmp": $new_image = imagecreatefromwbmp($current_image); break; default: $new_image = imagecreatefromgif($current_image); } // Capture the original size of the uploaded image list($width,$height) = getimagesize($current_image); if(isset($this->new_width) || isset($this->new_height)) { if(isset($this->new_width) && !isset($this->new_height) || $this->new_height < 1) { $this->new_width = ($this->new_width < 1 ? $width: $this->new_width); $this->new_height = ($height / $width) * $this->new_width; } elseif(isset($this->new_height) && !isset($this->new_width) || $this->new_width < 1) { $this->new_height = ($this->new_height < 1 ? $height: $this->new_height); $this->new_width = ($height / $width) * $this->new_height; } else { $this->new_height = ($this->new_height < 1 ? $height: $this->new_height); $this->new_width = ($this->new_width < 1 ? $width: $this->new_width); } } else { $this->new_height = ($height / 100) * $this->avatar_resize; $this->new_width = ($width / 100) * $this->avatar_resize; } $tmp_image = imagecreatetruecolor($this->new_width,$this->new_height); imagecopyresampled($tmp_image,$new_image,0,0,0,0,$this->new_width,$this->new_height,$width,$height); switch($image_type) { case "jpg": return imagejpeg($tmp_image); break; case "jpeg": return imagejpeg($tmp_image); break; case "gif": return imagegif($tmp_image); break; case "png": return imagepng($tmp_image); break; case "bmp": return imagewbmp($tmp_image); break; default: return imagegif($tmp_image); } } /** *Function to get the image type * *Inputted image url is exploded to find the image extension *@param string image url *@return string image extension */ function Get_Image_Type($image) { $image_type = explode(".",$image); $image_type = $image_type[$this->avatar_count]; return $image_type; } /** *Function to generate the send the page headers * *Sends the correct page headers to the browser */ function Send_Page_Headers() { //header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("content-type: image/gif");//Image type } /** *Function to generate the check if the image was shown previosuly * *checks the session to find out what image was sent last *@return bool true if new image is different from last image, else runs in a loop */ function random_check() { if($_SESSION['num'] == $_SESSION['random']) { $_SESSION['random'] = mt_rand(0,$this->avatar_count); self::random_check(); } return true; } } ########################################### ###############-- Display Image --################## ########################################### $avatar = new avatar; if($avatar->random_check()) { $avatar->Send_Page_Headers(); $avatar->Generate_Image(); } $_SESSION['num'] = $_SESSION['random']; ?>
  4. I have already seen that lol, i suppose that you was trying to say that yes it is because of recreating the file, and with that function below glancing over it it will just find out if the file is an animation and tell you how many frames and not a way to recreate them.
  5. Ok i have made this half-way solution, just to make sure the code works. <?php error_reporting(E_ALL); /** *Page to show a different avatar each time * * *@package Avatar Randomness *@author Dean Whitehouse (aka Blade280891) - deanwhitehouse6@hotmail.com - http://www.djw-designs.com - http://www.djw-webdesign.awardspace.com */ session_start(); /* Begin sessions, for more info visit either: The php manual, http://uk.php.net/session or my sites tutorial on using sessions to protect pages, http://djw-webdesign.awardspace.com/code.php?snippet=9 */ $avatar_resize = 50; //The amount , in percent, to resize the avatar /* Stored the amount to resize the avatar by in a variable, for more info visit; Php manual, http://uk3.php.net/language.variables */ /* Uncomment these lines to change the image using set widths and heights, only un comment one to keep the image aspect ratio $new_width = 128;//In pixels $new_height = 264;//In pixels */ $avatars = array ( "../images/djw_logo.jpg", "http://spearbang.awardspace.com/Sonic-animated.gif", "http://spearbang.awardspace.com/Tails-salutes.gif", "http://spearbang.awardspace.com/Sonic-and-Shadow-transform.gif", "http://spearbang.awardspace.com/Knuckles2.gif" ); /* Store the avatars in an array, for more info on arrays visit; The php manual, http://uk3.php.net/array or my site, http://djw-webdesign.awardspace.com/code.php?snippet=8 */ $avatar_count = count($avatars); ########################################### ################- Functions -#################### ########################################### /** *Function to generate the avatar image. * *Selects an image, resizes the image and then sends the image and headers to the browser *@return string image */ function Generate_Image($avatars) { //print_r($_SESSION); //print_r($avatars); if(isset($_SESSION['random']))// check for the session that contains the random number then unset it. { unset($_SESSION['random']); /* Unset the session that stores the random image reference number, for more info; The php manual, http://uk.php.net/unset */ } $_SESSION['random'] = mt_rand(0,(count($avatars) - 1)); /* Generate a new number for the image reference number */ if(!isset($_SESSION['num'])) { $_SESSION['num'] = $_SESSION['random']; } return Resize_Image($avatars[$_SESSION['random']]); } /** *Function to resize the image. * *Resizes the inputted image *@param string image url *@return string new image url */ function Resize_Image($image) { $current_image = $image; $avatar_resize = 100; $image_type = Get_Image_Type($current_image); //echo $image_type; //http://uk.php.net/switch switch($image_type) { case "jpg": $new_image = imagecreatefromjpeg($current_image); break; case "jpeg": $new_image = imagecreatefromjpeg($current_image); break; case "gif": $new_image = imagecreatefromgif($current_image); break; case "png": $new_image = imagecreatefrompng($current_image); break; case "bmp": $new_image = imagecreatefromwbmp($current_image); break; default: $new_image = imagecreatefromgif($current_image); } // Capture the original size of the uploaded image list($width,$height) = getimagesize($current_image); if(isset($new_width) || isset($new_height)) { if(isset($new_width) && !isset($new_height) || $new_height < 1) { $new_width = ($new_width < 1 ? $width: $new_width); $new_height = ($height / $width) * $new_width; } elseif(isset($new_height) && !isset($new_width) || $new_width < 1) { $new_height = ($new_height < 1 ? $height: $new_height); $new_width = ($height / $width) * $new_height; } else { $new_height = ($new_height < 1 ? $height: $new_height); $new_width = ($new_width < 1 ? $width: $new_width); } } else { $new_height = ($height / 100) * $avatar_resize; $new_width = ($width / 100) * $avatar_resize; } //echo $width." - ".$new_width."<br>".$height." - ".$new_height; $tmp_image = imagecreatetruecolor($new_width,$new_height); imagecopyresampled($tmp_image,$new_image,0,0,0,0,$new_width,$new_height,$width,$height); switch($image_type) { case "jpg": return imagejpeg($tmp_image); break; case "jpeg": return imagejpeg($tmp_image); break; case "gif": return imagegif($tmp_image); break; case "png": return imagepng($tmp_image); break; case "bmp": return imagewbmp($tmp_image); break; default: return imagegif($tmp_image); } } /** *Function to get the image type * *Inputted image url is exploded to find the image extension *@param string image url *@return string image extension */ function Get_Image_Type($image) { $image_type = explode(".",$image); $image_type = $image_type[(count($image_type) - 1)]; return $image_type; } /** *Function to generate the send the page headers * *Sends the correct page headers to the browser */ function Send_Page_Headers($image_type = "") { //header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("content-type: image/gif");//Image type } /** *Function to generate the check if the image was shown previosuly * *checks the session to find out what image was sent last *@return bool true if new image is different from last image, else runs in a loop */ function random_check($avatar_count) { if($_SESSION['num'] == $_SESSION['random']) { $_SESSION['random'] = mt_rand(0,($avatar_count -1)); random_check($avatar_count); } return true; } /** *Function to generate a random number between 0 and the amount of avatars stored * *uses mt_rand to generate a random number *@return integer random number */ function Generate_Random() { return mt_rand(0,$avatar_count); /* Generate a random number between 0 and the amount of avatar images stored in the array For more information about mt_rand visit; http://uk.php.net/mt_rand */ } ########################################### ###############-- Display Image --################## ########################################### if(random_check($avatar_count)) { Send_Page_Headers(); (Generate_Image($avatars)); } $_SESSION['num'] = $_SESSION['random']; ?> But now i have a problem that animated files don't play animations, i assume this is due to the image being recreated?
  6. Yeah, i dunno, i will try again on Saturday or something when i am not tired. Would of saved me a lot of time if my host didn't just say 500 internal error :s
  7. Hmm i was hoping to keep it simpler than that, i might just change it to OOP and that will make it easier/simpler for me
  8. Yep that kills the page, which it shouldn't, because the image link is fine Edit; according to my error reporting $avatars and $avatar_count are not defined :s Surely i don't need to pass them to the function via an argument?
  9. You can use a db to store the houses or whatever and then check for a column to see if it is sold or not and display the unsold ones.
  10. No, $new_width echos 0 $width,$height and $new_height don't print anything , i assume they are not being set. The image is not being saved to the folder.
  11. Yes that is JS, please ask in the JS section
  12. Just make a link that goes to the page e.g. <a href="upload.php">Upload another image</a> or do you mean using JS?
  13. Ok, so i have decided to rewrite my random avatar code and has not worked at all., lol. So here is my problem, when i first ran the code it caused a 500 internal server error, then i found that a function named random_check was causing this and further debugging showed that $avatar_count and $_SESSION['num']; are not defined. So i have tried to fix it and cannot find why its not working, any help is appreciated. <?php /** *Page to show a different avatar each time * * *@package Avatar Randomness *@author Dean Whitehouse (aka Blade280891) - deanwhitehouse6@hotmail.com - http://www.djw-designs.com - http://www.djw-webdesign.awardspace.com */ session_start(); if(isset($_SESSION['random']))// check for the session that contains the random number then unset it. { unset($_SESSION['random']); /* Unset the session that stores the random image reference number, for more info; The php manual, http://uk.php.net/unset */ } $_SESSION['random'] = Generate_Random(); /* Generate a new number for the image reference number */ if(!isset($_SESSION['num'])) { $_SESSION['num'] = $_SESSION['random']; } /* Begin sessions, for more info visit either: The php manual, http://uk.php.net/session or my sites tutorial on using sessions to protect pages, http://djw-webdesign.awardspace.com/code.php?snippet=9 */ $avatar_resize = 50; //The amount , in percent, to resize the avatar /* Stored the amount to resize the avatar by in a variable, for more info visit; Php manual, http://uk3.php.net/language.variables */ /* Uncomment these lines to change the image using set widths and heights, only un comment one to keep the image aspect ratio $new_width = 128;//In pixels $new_height = 264;//In pixels */ $avatars = array ( "http://spearbang.awardspace.com/Sonic-animated.gif", "http://spearbang.awardspace.com/Tails-salutes.gif", "http://spearbang.awardspace.com/Sonic-and-Shadow-transform.gif", "http://spearbang.awardspace.com/Knuckles2.gif" ); /* Store the avatars in an array, for more info on arrays visit; The php manual, http://uk3.php.net/array or my site, http://djw-webdesign.awardspace.com/code.php?snippet=8 */ $avatar_count = count($avatars); ########################################### ################- Functions -#################### ########################################### /** *Function to generate the avatar image. * *Selects an image, resizes the image and then sends the image and headers to the browser *@return string image */ function Generate_Image() { return Resize_Image($avatars[$_SESSION['random']]); } /** *Function to resize the image. * *Resizes the inputted image *@param string image url *@return string new image url */ function Resize_Image($image) { $current_image = $image; $image_type = Get_Image_Type($current_image); echo $image_type; //http://uk.php.net/switch switch($image_type) { case "jpg" || "jpeg": $new_image = imagecreatefromjpeg($current_image); break; case "gif": $new_image = imagecreatefromgif($current_image); break; case "png": $new_image = imagecreatefrompng($current_image); break; case "bmp": $new_image = imagecreatefromwbmp($current_image); break; default: $new_image = imagecreatefromgif($current_image); } // Capture the original size of the uploaded image list($width,$height) = getimagesize($new_image); if(isset($new_width) || isset($new_height)) { if(isset($new_width) && !isset($new_height) || $new_height < 1) { $new_width = ($new_width < 1 ? $width: $new_width); $new_height = ($height / $width) * $new_width; } elseif(isset($new_height) && !isset($new_width) || $new_width < 1) { $new_height = ($new_height < 1 ? $height: $new_height); $new_width = ($height / $width) * $new_height; } else { $new_height = ($new_height < 1 ? $height: $new_height); $new_width = ($new_width < 1 ? $width: $new_width); } } else { $new_height = ($height / 100) * $avatar_resize; $new_width = ($width / 100) * $avatar_resize; } echo $widht." - ".$new_width."<br>".$height." - ".$new_hieght; $tmp_image = imagecreatetruecolor($new_width,$new_height); imagecopyresampled($tmp_image,$new_image,0,0,0,0,$new_width,$new_height,$width,$height); return $tmp_image; } /** *Function to get the image type * *Inputted image url is exploded to find the image extension *@param string image url *@return string image extension */ function Get_Image_Type($image) { $image_type = explode(".",$image); $image_type = $image_type[count($image_type)]; return $image_type; } /** *Function to generate the send the page headers * *Sends the correct page headers to the browser */ function Send_Page_Headers($image_type = "") { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("content-type: image/gif");//Image type } /** *Function to generate the check if the image was shown previosuly * *checks the session to find out what image was sent last *@return bool true if new image is different from last image, else runs in a loop */ function random_check() { if($_SESSION['num'] == $_SESSION['random']) { $_SESSION['random'] = mt_rand(0,$avatar_count); random_check(); } return true; } /** *Function to generate a random number between 0 and the amount of avatars stored * *uses mt_rand to generate a random number *@return integer random number */ function Generate_Random() { return mt_rand(0,$avatar_count); /* Generate a random number between 0 and the amount of avatar images stored in the array For more information about mt_rand visit; http://uk.php.net/mt_rand */ } ########################################### ###############-- Display Image --################## ########################################### //if(random_check()) //{ //Send_Page_Headers(); echo (Generate_Image()); //} $_SESSION['num'] = $_SESSION['random']; ?> Edit: This is the output
  14. change mail ("$email", 'Statement for', "Thank You!", $headers); to if( mail ("$email", 'Statement for', "Thank You!", $headers)) echo "Sent"; else echo "failed";
  15. Ok have a look at the php manual about headers, and also try removing the function on the email address (to).
  16. function returning() { return "Code"; } function echoing() { echo "Code"; } echo echoing()." <br> ".returning();
  17. Try $content .= "<div id=\"full_content\"> Shopping Cart<br /> ".showCart()." </div>"; Or the best way would be to remake the function
  18. Huh? Just put the list of JS files at the top of the page, you seem to be making this more complicated than it is
  19. You need to add it to the array before doing the loop.
  20. And then what if they want to check for a whole range of different numbers, they would need an array from 0 to 9, when they could just something like *(0-9) (or whtever it is)
×
×
  • 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.