Forum Moderators: coopster
// upload the file if it exists
$file= uploadImage($_POST["uploadform"]);
// Create a Thumbnail if an image exists
if ($file != "no file")
{
$date = date("YmdHis");
$imgArr = split('[/]', $file);
$imgNameOnly = $imgArr[sizeof($imgArr)-1];
$folderPath = "";
for ($i=0; $i<sizeof($imgArr)-1; $i++)
$folderPath .= $imgArr[$i] . "/" ;$photoPathName = $folderPath . $date . "_" . $imgNameOnly;
$thumbNailPathName = $folderPath . "thumb_" . $date . "_" . $imgNameOnly;
$imgType = getImgType($imgNameOnly);
// Create a resized image of the orig. a mx of 400 pixels
[b]$photo=new Thumbnail(400,400);[/b]
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$photo->loadData($image,$imgType);
// Build the thumbnail and store as a file
$photo->buildThumb($photoPathName);
chmod("$photoPathName", 0666);
// Instantiate the thumbnail
$tn=new Thumbnail(100,100);
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$tn->loadData($image,$imgType);
// Build the thumbnail and store as a file
$tn->buildThumb($thumbNailPathName);
// delete the source file that is potentially large
unlink($file);
chmod("$thumbNailPathName", 0666);
}
Then you could use if/else to decide if you want to resize.
// upload the file if it exists
$file= uploadImage($_POST["uploadform"]);
// Create a Thumbnail if an image exists
if ($file != "no file")
{
$date = date("YmdHis");
$imgArr = split('[/]', $file);
$imgNameOnly = $imgArr[sizeof($imgArr)-1];
$folderPath = "";
for ($i=0; $i<sizeof($imgArr)-1; $i++)
$folderPath .= $imgArr[$i] . "/" ;$photoPathName = $folderPath . $date . "_" . $imgNameOnly;
$thumbNailPathName = $folderPath . "thumb_" . $date . "_" . $imgNameOnly;
$imgType = getImgType($imgNameOnly);
// Create a resized image of the orig. a mx of 400 pixels
$foo = getimagesize("$photo");
$width=$foo[0];
if($width < '400'){
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$photo->loadData($image,$imgType);
// Build the thumbnail and store as a file
$photo->buildThumb($photoPathName);
chmod("$photoPathName", 0666);
// Instantiate the thumbnail
$tn=new Thumbnail(100,100);
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$tn->loadData($image,$imgType);
// Build the thumbnail and store as a file
$tn->buildThumb($thumbNailPathName);
// delete the source file that is potentially large
unlink($file);
chmod("$thumbNailPathName", 0666);
} else {
$photo=new Thumbnail(400,400);
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$photo->loadData($image,$imgType);
// Build the thumbnail and store as a file
$photo->buildThumb($photoPathName);
chmod("$photoPathName", 0666);
// Instantiate the thumbnail
$tn=new Thumbnail(100,100);
// Load an image into a string (this could be from a database)
$image=file_get_contents($file);
// Load the image data
$tn->loadData($image,$imgType);
// Build the thumbnail and store as a file
$tn->buildThumb($thumbNailPathName);
// delete the source file that is potentially large
unlink($file);
chmod("$thumbNailPathName", 0666);
}
\\above is my edit
}
$foo = getimagesize("urlgoeshere");
$picwidth=$foo[0];
$picheight=$foo[1];echo $picheight;
I'm trying to test out the getimagesize function - and learn how it works. Afterwords - I'll implement it into the code I have already posted in other posts. I've tried the above code - with the url of an image - and it seems to work with outputting the image's height. So how would I implement those ideals into the code that I've posted in the first post? Maybe an if/else statement comparing a smaller then satement of 400 pixels? Any thoughts on how I can put this together? Thanks!
$foo = getimagesize("urlgoeshere");
$picwidth=$foo[0];
$picheight=$foo[1];
if (($picwidth > 400) && ($picheight > 400)) {
// resize
}
else {
// image is smaller than 400 so no point in resizing.
}