note 34573 deleted from function.imagecopyresampled by cece

From: Date: Sat, 16 Aug 2003 20:00:55 +0000
Subject: note 34573 deleted from function.imagecopyresampled by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54443@lists.php.net to get a copy of this message
Note Submitter: mail@intoit.com.au ---- On my page, an admin would upload an image of any size into mysql. On page display This script resizes the image to a max of 80 x 100 and creates a .jpg thumbnail if 1 does not already exist. The images were reduced from 200KB to 3KB with very good image quality. $query=mysql_query("select playerprofile.teamid, playerprofile.name, playerprofile.position, playerprofile.nickname, playerprofile.favteam, playerprofile.despiseteam, playerprofile.sportsman, playerprofile.favourite, playerprofile.embarrasing, playerprofile.themesong, playerprofile.guest1, playerprofile.guest2, playerprofile.guest3, teams.name, playerprofile.filename FROM playerprofile, teams WHERE playerprofile.teamid=teams.id and playerprofile.id=$id")or die(mysql_error()); $get=mysql_fetch_row($query); $teamid=$get[0]; $name=$get[1]; $position=$get[2]; $nickname=$get[3]; $favteam=$get[4]; $despiseteam=$get[5]; $sportsman=$get[6]; $favourite=$get[7]; $embarrasing=$get[8]; $themesong=$get[9]; $guest1=$get[10]; $guest2=$get[11]; $guest3=$get[12]; $teamname=$get[13]; $filename=$get[14]; $extension=strtolower(strstr"$filename", ".")); if(!$filename=="") { $imagehw = GetImageSize("http://.../getpic.php?id=$id"); $imagewidth = $imagehw[0]; $imageheight = $imagehw[1]; //get new sizes to make images max of 80 x 100 and in //proportion if($imagewidth > 80) { $percent=80/$imagewidth; $imagewidth=80; $imageheight=$percent * $imageheight; } if($imageheight > 100) { $percent=100/$imageheight; $imageheight=100; $imagewidth=$percent * $imagewidth; } //now resize and create thumbnail. Use the outputed //thumbnail for display. Keep the original large file in database //detect if thumbnail has already been created. If yes then //just go to display, no need to do routine again if(!file_exists('/filepath/$id.jpg')) { if($extension==".jpg" or $extension==".jpeg") { $src_img = imagecreatefromjpeg("http://..../getpic.php?id=$id"); } else if($extension==".gif") { $src_img = imagecreatefromgif("http://..../getpic.php?id=$id"); } else if($extension==".bmp") { $src_img = imagecreatefromwbmp("http://..../getpic.php?id=$id"); } $dstimage = imagecreatetruecolor($imagewidth, $imageheight); imagecopyresampled ($dstimage, $src_img, 0, 0, 0, 0, $imagewidth, $imageheight, $imagehw[0], $imagehw[1]); imagejpeg ($dstimage, "/filepath/$id.jpg", 75); ImageDestroy($src_img); ImageDestroy($dstimage); } echo "<img src='/img/profiles/$id.jpg' border='0'>"; }

« previous php.notes (#54443) next »