Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // https://code.tutsplus.com/tutorials/how-to-create-a-thumbnail-image-in-php--cms-36421
- // File Name : thumbimage.class.php
- class ThumbImage
- {
- private $source;
- public function __construct($sourceImagePath)
- {
- $this->source = $sourceImagePath;
- }
- public function createThumb($destImagePath, $thumbWidth=100)
- {
- $sourceImage = imagecreatefromjpeg($this->source);
- $orgWidth = imagesx($sourceImage);
- $orgHeight = imagesy($sourceImage);
- $thumbHeight = floor($orgHeight * ($thumbWidth / $orgWidth));
- $destImage = imagecreatetruecolor($thumbWidth, $thumbHeight);
- imagecopyresampled($destImage, $sourceImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $orgWidth, $orgHeight);
- imagejpeg($destImage, $destImagePath);
- imagedestroy($sourceImage);
- imagedestroy($destImage);
- }
- }
- ?>
- <?php
- // Another File
- require "thumbimage.class.php";
- $objThumbImage = new ThumbImage("/web/uploads/orig.jpg");
- $objThumbImage->createThumb("/web/uploads/thumb.jpg", 125);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement