Jump to content

The Reverend

Members
  • Posts

    11
  • Joined

  • Last visited

The Reverend's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. The Reverend

    thumbnail

    Here's some code that will help you out:It's an object oriented thumbnail class. <?php//requires GD 2.0.1 or higherclass ThumbnailImage{ private $image; //not applicable to gif private $quality = 100; private $mimetype; private $imageproperties; private $initialfilesize; public function __construct($file, $thumbnailsize = 100){ //check path is_file($file) or die ("File: $file doesn't exist."); $this->initialfilesize = filesize($file); $this->imageproperties = getimagesize($file) or die ("Incorrect file type."); // new function image_type_to_mime_type $this->mimetype = image_type_to_mime_type($this->imageproperties[2]); //create image switch($this->imageproperties[2]){ case IMAGETYPE_JPEG: $this->image = imagecreatefromjpeg($file); break; case IMAGETYPE_GIF: $this->image = imagecreatefromgif($file); break; case IMAGETYPE_PNG: $this->image = imagecreatefrompng($file); break; default: die("Couldn't create image."); } $this->createThumb($thumbnailsize); } public function __destruct(){ if(isset($this->image)){ imagedestroy($this->image); } } public function getImage(){ header("Content-type: $this->mimetype"); switch($this->imageproperties[2]){ case IMAGETYPE_JPEG: imagejpeg($this->image,"",$this->quality); break; case IMAGETYPE_GIF: imagegif($this->image); break; case IMAGETYPE_PNG: imagepng($this->image,"",$this->quality); break; default: die("Couldn't create image."); } } public function getMimeType(){ return $this->mimetype; } public function getQuality(){ $quality = null; if($this->imageproperties[2] == IMAGETYPE_JPEG || $this->imageproperties[2] == IMAGETYPE_PNG){ $quality = $this->quality; } return $quality; } public function setQuality($quality){ if($quality > 100 || $quality < 1){ $quality = 75; } if($this->imageproperties[2] == IMAGETYPE_JPEG || $this->imageproperties[2] == IMAGETYPE_PNG){ $this->quality = $quality; } } public function getInitialFileSize(){ return $this->initialfilesize; } private function createThumb($thumbnailsize){ //array elements $srcW = $this->imageproperties[0]; $srcH = $this->imageproperties[1]; //only adjust if larger than reduction size if($srcW >$thumbnailsize || $srcH > $thumbnailsize){ $reduction = $this->calculateReduction($thumbnailsize); //get proportions $desW = $srcW/$reduction; $desH = $srcH/$reduction; $copy = imagecreatetruecolor($desW, $desH); imagecopyresampled($copy,$this->image,0,0,0,0,$desW, $desH, $srcW, $srcH) or die ("Image copy failed."); //destroy original imagedestroy($this->image); $this->image = $copy; } } private function calculateReduction($thumbnailsize){ //adjust $srcW = $this->imageproperties[0]; $srcH = $this->imageproperties[1]; if($srcW < $srcH){ $reduction = round($srcH/$thumbnailsize); }else{ $reduction = round($srcW/$thumbnailsize); } return $reduction; }}?> <?php//this file will be the src for an img tagrequire 'ThumbnailImage.php';$path = @$_GET["path"];$maxsize = @$_GET["size"];if(!isset($maxsize)){ $maxsize=100;}if(isset($path)){ $thumb = new ThumbNailImage($path, $maxsize); $thumb->getImage();}?> You create these as ThumbnailImage.php and image.php. You can resize the image simply by refering with path and size as your $_GET variables.
  2. I went straight from HTML and CSS to PHP and now Javascript. I think it really depends on what you plan on doing. If you are just generally building sites, I think you'll be using PHP more often than XML. It doesn't hurt to be familiar with XML though as it is a very useful tool.
  3. I'm not sure what you're asking. I think you may be confused a bit. $_GET variables are transmitted through urls but they generally aren't big strings of data. Are you using a database?
  4. I don't see anything wrong with it then. I setup a table to the same specs he's given on my XAMPP deal on my computer and ran the query, it works fine.I think of =& as buy in this case btw. My beer drinking class is a work in progress.
  5. I don't know how it is on your server, but the one I use requires syntax using ` surrounding the table name and fields, like this: INSERT INTO `site_uploads` (`uid`, `title`, `desc`, `file`, `uploaded`) VALUES ('1', 'Notepad 2', 'Try it!', 'Notepad 2.zip', '2006-08-03')
  6. I've worked on a number of sites, but this one is mine and it's my baby. This is the third incarnation of it since I built it.http://www.ninercaphell.com
  7. Thank you justsomeguy for explaining that, I probably should have in the first place. It's extremely easy to use, and it's not to hard to add new codes to if you follow the formatting carefully. This particular one is fairly customized for my own use. If you need to add tags it's fairly simple.start out with "/"Then I assume you're gonna have some kind of tag like this [r], simply escape the brackets\[r\]add the (.*?) in the middle, this is the wildcard.then close the tag the same way it's opened, but you have to escape the / as well\[\/r\]then simply end it with /isthe end result being'/\[r\](.*?)\[\/r\]/is'Hope this helps, this function has been a lifesaver for me.btw, if you didn't notice, this function will also convert \n to<br />
  8. I'm a big fan of PHP. I've been using it a lot the last several months and it's been able to do just about everything I've needed.
  9. Name: Chris JamesLocation: Bay AreaAge: 21How I roll: I wanna be the best at everything I doI know: XHTML, CSS, PHP, XML, SQLI know a bit: Javascript, XSL, FlashHobbies:Drums, Guitar, Football, web design, wasting time on the internet
  10. Depends on what you want it to do with the webpage. You can have it read the page and do something with what it read. What is the purpose of reading it in your case?
  11. Regex is the answer my children function bb($str){ $str = htmlentities($str); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[center\](.*?)\[\/center\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is','/\[video\](.*?)\[\/video\]/is', '/\[move\](.*?)\[\/move\]/is', '/\[img\=(.*?)\]/is', '/\[hr\]/i', '/\[s\](.*?)\[\/s\]/is', '/\[o\](.*?)\[\/o\]/is', '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[img w\=(.*?)\](.*?)\[\/img\]/is', '/\[sup\](.*?)\[\/sup\]/is', '/\[sub\](.*?)\[\/sub\]/is', '/\[tr\](.*?)\[\/tr\]/is', '/\[td\](.*?)\[\/td\]/is', '/\[table\](.*?)\[\/table\]/is', '/\[tr (.*?)\](.*?)\[\/tr\]/is', '/\[td (.*?)\](.*?)\[\/td\]/is', '/\[table (.*?)\](.*?)\[\/table\]/is', '/\[code\](.*?)\[\/code\]/is', '/\[email\](.*?)\[\/email\]/is', '/\[email\=(.*?)\](.*?)\[\/email\]/is', '/\[quote\](.*?)\[\/quote\]/is', '/\[quote\=(.*?)\](.*?)\[\/quote\]/is', '/\n/i' ); $replace = array( '<strong>$1</strong>', '<center>$1</center>', '<em>$1</em>', '<u>$1</u>','<object width="425" height="350"><param name="movie" value="$1"></param><embed src="$1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>', '<marquee>$1</marquee>', '<img src="$1" />', '<hr />', '<span style="text-decoration:line-through;">$1</span>', '<span style="text-decoration:overline;">$1</span>', '<span style="font-family:$1">$2</span>', '<a href="$1" target="_blank">$2</a>', '<a href="$1" target="_blank">$1</a>', '<img src="$1" />', '<img src="$2" width="$1"/>', '<sup>$1</sup>', '<sub>$1</sub>', '<tr>$1</tr>', '<td>$1</td>', '<table>$1</table>', '<tr $1>$2</tr>', '<td $1>$2</td>', '<table $1>$2</table>', '<b>Code:</b><br /><table class="code"><tr><td class="code">$1</td></tr></table>', '<a href="mailto:$1">$1</a>', '<a href="mailto:$1">$2</a>', '<table width=\'60%\' align=\'center\' border=\'1\' bgcolor="#999999"><tr><td><b>Quote:</b></td></tr><tr><td width=\'100%\'><i>$1</i></td></tr></table>', '<table width=\'60%\' align=\'center\' border=\'1\' bgcolor="#999999"><tr><td><b>Source: $1</b></td></tr><tr><td width=\'100%\'><i>$2</i></td></tr></table>', '<br />' ); $str = preg_replace ($search, $replace, $str); return $str; };
×
×
  • Create New...