i have this function. the idea of the function is to create a thumbnail and a viewable image which go into seperate folders one goes into a folder called thumbs and one goes into viewed. they are both sub folders of the folder images.
<?php
function thumbnail($image, $maxWidth, $maxHeight) {
$pinfo = pathinfo($image);
$tmb_name = $pinfo['dirname'].'/thumbs/'.$pinfo['filename'].'_tmb.'.$pinfo['extension'];
$quality = 100; // imagejpeg() accepts quality as the third variable, not a path.
switch($pinfo['extension']) :
case "jpg" :
case "jpeg" :
$fileType = "jpeg";
$imageCreateFunction = "imagecreatefromjpeg";
$imageOutputFunction = "imagejpeg";
break;
case "png" :
$fileType = "png";
$imageCreateFunction = "imagecreatefrompng";
$imageOutputFunction = "imagepng";
break;
case "gif" :
$fileType = "gif";
$imageCreateFunction = "imagecreatefromgif";
$imageOutputFunction = "imagegif";
break;
endswitch;
list($originalWidth, $originalHeight) = getimagesize($image);
$x_ratio = $maxWidth / $originalWidth;
$y_ratio = $maxHeight / $originalHeight;
// check that the new width and height aren't bigger than the original values.
// the new values are higher than the original, don't resize or we'll lose quality
if (($originalWidth <= $maxWidth) && ($originalHeight <= $maxHeight)) {
$newWidth = $originalWidth;
$newHeight = $originalHeight;
} else if (($x_ratio * $originalHeight) < $maxHeight) {
$newHeight = ceil($x_ratio * $originalHeight);
$newWidth = $maxWidth;
} else {
$newWidth = ceil($y_ratio * $originalWidth);
$newHeight = $maxHeight;
}
$src = $imageCreateFunction($image);
$dst = imagecreatetruecolor($newWidth, $newHeight);
// Resample
imagecopyresampled($dst, $src, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
// Save image
$imageOutputFunction($dst, $tmb_name, $quality);
imagedestroy($src);
imagedestroy($dst);
return true;
}
?>
i need to change where the file goes in this file and then be able to say where i want to do it when i call it in my upload file.
this is what i do to run the function:
$image = $target_path;
$maxHeight = 90; $maxWidth = 150;
include 'thumbnail_function.php'; // Include the function file
thumbnail($image, $maxWidth, $maxHeight); // Call the function with a width of 90...
$maxWidth = 350; $maxHeight = 300; // Redefine the size.
thumbnail($image, $maxWidth, $maxHeight); // Call the function again with a width of 350
i then would need to add to my query to write the image paths of the two images i just create. could someone show me what i would need to change in my function and upload file and query please:
query:
// Gather all required data
$name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
$mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
$size = intval($_FILES['uploaded_file']['size']);
$image_path = $dbLink->real_escape_string($target_path);
$gallery_type = $dbLink->real_escape_string($_POST['gallery_type']);
$desc = $dbLink->real_escape_string($_POST['desc']);
$image_path = $dbLink->real_escape_string($target_path);
$tmb_name = $dbLink->real_escape_string($tmb_name);
//query to insert the data i had gathered into the database
$query = "INSERT INTO `images` (`name`, `size`, `created`, `image_path`, `gallery_type_id`, `desc`, `thumbnail_path` )
VALUES ('{$name}', {$size}, NOW(), '{$image_path}', '{$gallery_type}', '{$desc}', '{$tmb_name}')";