Prior, when I ran the below code, I was erroring out. Upon further trouble shooting, I discovered that I was erroring out, because the path to the image was wrong. I updated the path to the image, and I am no longer erroring out. It is running. The problem now is, is that when I run the code, I am not seeing the images.
Any suggestions would be appreciated. I am running it on xampp - my end goal is to view thumb images
Code
Beginning of example.php code, which is called first
End of example.php code, which is called first
Beginning of thumbimage.class.php
End of thumbimage.class.php
Any suggestions would be appreciated. I am running it on xampp - my end goal is to view thumb images
Code
Beginning of example.php code, which is called first
PHP:
<?php
// example.php
#require_once $_SERVER['DOCUMENT_ROOT'].'/common/configs/config_templates.inc.php';
require "thumbimage.class.php";
/* $objThumbImage = new ThumbImage("/web/uploads/orig.jpg");
$objThumbImage->createThumb("/web/uploads/thumb.jpg", 125); */
$objThumbImage = new ThumbImage("web/uploads/orig.jpeg"); // IMPORTANT - THIS LINE WORKS FINE
$objThumbImage->createThumb("web/uploads/thumb.jpeg", 125);
?>
End of example.php code, which is called first
Beginning of thumbimage.class.php
PHP:
<?php
// 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);
}
}
?>
Last edited by a moderator: