new image show system, allowing dynamic preview images

This commit is contained in:
Thomas Weinhold 2020-09-26 21:32:58 +02:00
commit dfda07ae1c
8 changed files with 193 additions and 53 deletions

View file

@ -129,4 +129,26 @@ function OtherGetIcon ($IconName,$CssClass)
return $RetVal;
}
// Returns a html <img> tag
function OtherGetPictureImg($part_id, $max_width=0, $max_height=0) {
// create anchor tag
$tag = "<a href=\"part_picture.php?PartId=$part_id\">";
// create img tag
$tag .= "<img src=\"part_picture.php?PartId=$part_id";
if ($max_width > 0) $tag .= "&MaxWidth=$max_width";
if ($max_height > 0) $tag .= "&MaxHeight=$max_height";
$tag .= "\""; // finish src attribute
$tag .= " alt=\"picture of part $part_id\"";
$tag .= ">"; // finish img tag
// close link
$tag .= '</a>';
return $tag;
}
?>

View file

@ -139,6 +139,8 @@ PartsObsolete = Obsolete
PartsObsoleteOnly = Only Obsolete
PartsObsoleteNon = Non Obsolete
PartsObsoleteAll = All Parts
PartsPreviewImageYes = Show Preview Images
PartsPreviewImageNo = Hide Preview Images
PartsType = Type
PartsStorage = Store
PartsValues = Values

View file

@ -139,6 +139,8 @@ PartsObsolete = Obsolet
PartsObsoleteOnly = nur Obsolet
PartsObsoleteNon = keine Obsolete
PartsObsoleteAll = alle Bauteile
PartsPreviewImageYes = Vorschaubilder anzeigen
PartsPreviewImageNo = keine Vorschaubilder
PartsType = Typ
PartsStorage = Lager
PartsValues = Werte

View file

@ -106,6 +106,13 @@ $GlobalContent .= '</div>'."\n";
/////////
// Filter
$GlobalContent .= '<div id="PartFilter">'."\n";
//ShowImage
if (!isset($_SESSION['FilterShowPreviewImage'])) $_SESSION['FilterShowPreviewImage'] = "TRUE";
if (isset($_POST['FilterShowPreviewImage'])) $_SESSION['FilterShowPreviewImage']=$_POST['FilterShowPreviewImage'];
$GlobalContent .= ' <form action="index.php?Page=PartsByType" method="post">'."\n";
$GlobalContent .= ' <input type="radio" name="FilterShowPreviewImage" value="TRUE" onClick="javascript:this.form.submit()" '.(($_SESSION['FilterShowPreviewImage']=="TRUE")? "checked":"").'>'.LangSpellHtml('PartsPreviewImageYes')."\n";
$GlobalContent .= ' <input type="radio" name="FilterShowPreviewImage" value="FALSE" onClick="javascript:this.form.submit()" '.(($_SESSION['FilterShowPreviewImage']!="TRUE")? "checked":"").'>'.LangSpellHtml('PartsPreviewImageNo')."\n";
$GlobalContent .= ' </form>'."<br>\n";
//Obsolete Filter
if (!isset($_SESSION['FilterObsolete'])) $_SESSION['FilterObsolete']="NonObsolete";
if (isset($_POST['FilterObsolete'])) $_SESSION['FilterObsolete']=$_POST['FilterObsolete'];
@ -143,6 +150,10 @@ $GlobalContent .= '<table>'."\n";
// PartList Table Head
$GlobalContent .= '<tr>';
// PreviewImage
if ($_SESSION['FilterShowPreviewImage'] == "TRUE") {
$GlobalContent .= '<th>Image</th>';
}
//Name
$GlobalContent .= '<th><a href="index.php?Page=PartsByType&SortBy=Name" target="_top">';
$GlobalContent .= LangSpellHtml('PartsName')." ";
@ -212,21 +223,30 @@ $PartListQuery = mysqli_query($GlobalMysqlHandler, $PartListQuery);
while ($Parts = mysqli_fetch_array($PartListQuery))
{
$GlobalContent .= ' <tr>';
// PreviewImage
if ($_SESSION['FilterShowPreviewImage'] == "TRUE") {
$GlobalContent .= '<td>';
if ($Parts['PicturePath'] != "") {
$GlobalContent .= OtherGetPictureImg($Parts['Id'], 100, 50);
}
$GlobalContent .= '</td>';
}
// Name, Value1, Value2, Value3
$GlobalContent .= ' <td><a href="index.php?Page=ShowPart&PartId='.$Parts['Id'].'" target="_top"><strong>'.$Parts['Name'].'</strong></a> '.$Parts['ShortDesc'].' </td>';
if (isset($TypeValues[0][0]) && $TypeValues[0][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value1']).$TypeValues[0][1].'</td>';
if (isset($TypeValues[1][0]) && $TypeValues[1][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value2']).$TypeValues[1][1].'</td>';
if (isset($TypeValues[2][0]) && $TypeValues[2][0]) $GlobalContent .= ' <td>'.OtherFloatToSiPrefix ($Parts['Value3']).$TypeValues[2][1].'</td>';
//////////
// Package
$PackageQuery = "SELECT `Name` FROM `Packages` WHERE `Id` = ".$Parts['PackageId'];
$PackageQuery = mysqli_query($GlobalMysqlHandler, $PackageQuery);
if (mysqli_num_rows($PackageQuery))
{
if (mysqli_num_rows($PackageQuery)) {
$Package=mysqli_fetch_array($PackageQuery);
$GlobalContent .= '<td>'.$Package['Name'].'</td>';
}
else
{
} else {
$GlobalContent .= '<td>-</td>';
}
$GlobalContent .= '<td>'.$Parts['Qty'].(($Parts['MinQty'])? "/".$Parts['MinQty']:"").'</td>';

View file

@ -79,8 +79,7 @@ global $GlobalMysqlHandler;
$GlobalContent .= '<input type="submit" value="'.LangSpellHtml('ButtonUpload').'"class="Button">';
$GlobalContent .= '</form><br>';
}
$GlobalContent .= '<img src="'.$GlobalPictureDir.'/'.$Part['PicturePath'].'"><br><br>';
echo "IMAGE: " . $Part['PicturePath'] . "<br>\n";
$GlobalContent .= OtherGetPictureImg($PartId, 300, 600);
$GlobalContent .= '</div>'."\n";
////////////////

95
part_picture.php Normal file
View file

@ -0,0 +1,95 @@
<?php
// Script that generates image data for a requested part in fbsql_database
//
// possible GET valiables:
// PartId (required) - Id of part in databse
// MaxWidth (optional) - When given, image is scaled down to that maximum width
// MaxHeight (optional) - When given, image is scaled down to that maximum height
//main include code
include ("./includes/globals.php");
include ("./includes/load_config.php");
include ("./includes/log.php");
include ("./includes/language.php");
include ("./includes/mysql.php");
include ("./includes/other_functions.php");
// get part Id
if (!isset($_GET['PartId'])) {
exit("ERROR: PartId no given!");
}
$part_id = intval($_GET['PartId']);
// get picture path
$db_query = "SELECT PicturePath FROM `Parts` WHERE `Id` = $part_id;";
$db_result = mysqli_query($GlobalMysqlHandler, $db_query);
if ($db_result->num_rows == 0) {
exit("ERROR: PartId not found!");
}
$source_path = $GlobalPictureDir . "/" . $db_result->fetch_array()['PicturePath'];
// get image info
list($source_width, $source_height) = getimagesize($source_path);
$mime_type = mime_content_type($source_path);
// calculate new With and Height
$output_width = $source_width;
$output_height = $source_height;
$max_width = 0;
if (isset($_GET['MaxWidth'])) {
$max_width = intval($_GET['MaxWidth']);
if ($output_width > $max_width) {
$scale_factor = $max_width / $output_width;
$output_width *= $scale_factor;
$output_height *= $scale_factor;
}
}
$max_height = 0;
if (isset($_GET['MaxHeight'])) {
$max_height = intval($_GET['MaxHeight']);
if ($output_height > $max_height) {
$scale_factor = $max_height / $output_height;
$output_width *= $scale_factor;
$output_height *= $scale_factor;
}
}
// load image
if ($mime_type == 'image/jpeg') {
$source_image = imagecreatefromjpeg($source_path);
$output_image = imagecreatetruecolor($output_width, $output_height);
} else if ($mime_type == 'image/png') {
$source_image = imagecreatefrompng($source_path);
imagealphablending($source_image, true);
imagesavealpha($source_image, true);
$output_image = imagecreate($output_width, $output_height);
} else {
ErrorLog("Unkown mime type: " . $mime_type . "!");
exit("Can't handle requested mime-type.");
}
// resize
$res = imagecopyresized($output_image, $source_image, 0, 0, 0, 0, $output_width, $output_height, $source_width, $source_height);
if ($res !== True) {
$msg = "Cannot resize image: " . $source_path . "\n";
$msg .= "source: " . $source_width . "x" . $source_height;
$msg .= ", max: " . $max_width . "x" . $max_height;
$msg .= ", output: " . $output_width . "x" . $output_height;
ErrorLog($msg);
exit("Cannot resize image!");
}
// output as png
header('Content-Type: image/png');
imagepng($output_image);
imagedestroy($output_image);
imagedestroy($source_width);
?>