/ Published in: PHP
define ur thumbx
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Thumbnail { const PARENT_PATH = 'C:/Users/gonzaram/Desktop/'; protected $_directoryPath; protected $_width; protected $_height; protected $_targetPath; public function __construct($path) { $this->_directoryPath = $path; $this->_readDir($this->_directoryPath); return $this; } public function generate() { } foreach ($this->_files as $index => $file) { //This will set our output to 45% of the original size //$size = 0.45; //$thumb_w = $this->_width * $size; //$thumb_h = $this->_height * $size; $fileLocation = self::PARENT_PATH . $this->_directoryPath . DIRECTORY_SEPARATOR . $file; // Setting the resize parameters // Calculate the new size $ratio1 = $width / $this->_width; $ratio2 = $height / $this->_height; if($ratio1 > $ratio2) { $thumb_w = $this->_width;; $thumb_h = $height / $ratio1; } else { $thumb_h = $this->_height; $thumb_w = $width / $ratio2; } // Resizing the Image // Outputting a .jpg, you can make this gif or png if you want //notice we set the quality (third value) to 100 $destinationThumbnail = $this->_targetPath . 'thumb_' . $file; } } public function setWidth($width) { $this->_width = $width; return $this; } public function setHeight($height) { $this->_height = $height; return $this; } public function setTargetDirectory($target) { $this->_targetPath = $target; return $this; } private function _readDir($path) { $fullPath = self::PARENT_PATH . $path; foreach ($resources as $resource) { if ($resource != "." && $resource != "..") { $resourceDir = $fullPath . '/'. $resource; $this->_files[$resource] = $this->_readDir($path . '/' . $resource); } else { $this->_files[] = $resource; } } } return $this->_files; } } $thumbs = new Thumbnail('test'); $thumbs->setWidth(250) ->setHeight(250) ->generate(); echo "<pre>";