Fix no JPG images in TakePOS and other image improvements.

This commit is contained in:
andreubisquerra 2019-02-24 21:15:11 +01:00
parent dfd6a0feaa
commit 57ee8b7991
6 changed files with 57 additions and 76 deletions

View File

@ -110,6 +110,18 @@ div.description{
text-align:center;
}
div.catwatermark{
position:absolute;
top:3%;
left:3%;
width:20%;
background-color:black;
color:white;
text-align:center;
font-size: 20px;
display: none;
}
@media only screen and (max-aspect-ratio: 6/4) {
div.description{
min-height:20%;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

View File

@ -38,7 +38,6 @@ $query= GETPOST('query');
* View
*/
header('Content-Type: image/jpeg');
header('Cache-Control: max-age=604800, public, must-revalidate');
header('Pragma: cache');
@ -49,39 +48,27 @@ if ($query=="cat")
$object = new Categorie($db);
$result = $object->fetch($id);
$upload_dir = $conf->categorie->multidir_output[$object->entity];
$pdir = get_exdir($object->id, 2, 0, 0, $object, 'category') . $object->id ."/photos/";
$dir = $upload_dir.'/'.$pdir;
foreach ($object->liste_photos($dir) as $key => $obj)
{
$filename=$obj['photo'];
}
// The file
$filename = $dir.$filename;
if (!file_exists($filename)) $filename="empty.jpg";
// Dimensions
list($width, $height) = getimagesize($filename);
$new_width = $w;
$new_height = $h;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Add icon
$icon = imagecreatefromjpeg('add.jpg');
list($width, $height) = getimagesize('add.jpg');
$new_width = $w*0.3;
$new_height = $h*0.3;
$icon_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($icon_p, $icon, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopymerge($image_p, $icon_p, 0, 0, 0, 0, $new_width, $new_height, 100);
// Output
imagejpeg($image_p, null, 100);
{
if ($obj['photo_vignette'])
{
$filename=$obj['photo_vignette'];
}
else
{
$filename=$obj['photo'];
}
$viewfilename=$obj['photo'];
$file=DOL_URL_ROOT.'/viewimage.php?modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename);
header('Location: '.$file);
exit;
}
header('Location: ../../public/theme/common/nophoto.png');
}
elseif ($query=="pro")
{
@ -89,39 +76,13 @@ elseif ($query=="pro")
$objProd = new Product($db);
$objProd->fetch($id);
$dir .= get_exdir(0, 0, 0, 0, $objProd, 'product').$objProd->ref.'/';
$pdir .= get_exdir(0, 0, 0, 0, $objProd, 'product').$objProd->ref.'/';
foreach ($objProd->liste_photos($dir) as $key => $obj)
{
$filename=$obj['photo'];
}
$filename = $dir.$filename;
if (!file_exists($filename)){
$dir = $conf->product->multidir_output[$objProd->entity].'/'.$pdir;
foreach ($objProd->liste_photos($dir) as $key => $obj)
{
$filename=$obj['photo'];
}
$filename = $dir.$filename;
}
if (!file_exists($filename)) $filename="empty.jpg";
// Dimensions
list($width, $height) = getimagesize($filename);
$new_width = $w;
$new_height = $h;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
$image=$objProd->show_photos('product', $conf->product->multidir_output[$entity], 'small', 1);
preg_match( '@src="([^"]+)"@' , $image, $match );
$file = array_pop($match);
if ($file=="") header('Location: ../../public/theme/common/nophoto.png');
else header('Location: '.$file);
}
else
{

View File

@ -93,8 +93,9 @@ function PrintCategories(first){
for (i = 0; i < 14; i++) {
if (typeof (categories[parseInt(i)+parseInt(first)]) == "undefined") break;
$("#catdesc"+i).text(categories[parseInt(i)+parseInt(first)]['label']);
$("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
$("#catimg"+i).attr("src","genimg/?query=cat&id="+categories[parseInt(i)+parseInt(first)]['rowid']);
$("#catdiv"+i).data("rowid",categories[parseInt(i)+parseInt(first)]['rowid']);
$("#catwatermark"+i).show();
}
}
@ -117,12 +118,14 @@ function MoreCategories(moreorless){
for (i = 0; i < 14; i++) {
if (typeof (categories[i+(14*pagecategories)]) == "undefined"){
$("#catdesc"+i).text("");
$("#catimg"+i).attr("src","");
$("#catimg"+i).attr("src","genimg/empty.png");
$("#catwatermark"+i).hide();
continue;
}
$("#catdesc"+i).text(categories[i+(14*pagecategories)]['label']);
$("#catimg"+i).attr("src","genimg/?query=cat&w=55&h=50&id="+categories[i+(14*pagecategories)]['rowid']);
$("#catimg"+i).attr("src","genimg/?query=cat&id="+categories[i+(14*pagecategories)]['rowid']);
$("#catdiv"+i).data("rowid",categories[i+(14*pagecategories)]['rowid']);
$("#catwatermark"+i).show();
}
}
@ -131,16 +134,17 @@ function LoadProducts(position, issubcat=false){
$('#catimg'+position).animate({opacity: '1'}, 100);
if (issubcat==true) currentcat=$('#prodiv'+position).data('rowid');
else currentcat=$('#catdiv'+position).data('rowid');
if (currentcat=="") return;
if (currentcat==undefined) return;
pageproducts=0;
ishow=0; //product to show counter
jQuery.each(subcategories, function(i, val) {
if (currentcat==val.fk_parent){
$("#prodesc"+ishow).text(val.label);
$("#proimg"+ishow).attr("src","genimg/?query=cat&w=55&h=50&id="+val.rowid);
$("#proimg"+ishow).attr("src","genimg/?query=cat&id="+val.rowid);
$("#prodiv"+ishow).data("rowid",val.rowid);
$("#prodiv"+ishow).data("iscat",1);
$("#prowatermark"+ishow).show();
ishow++;
}
});
@ -150,18 +154,19 @@ function LoadProducts(position, issubcat=false){
while (idata < 30 && ishow < 30) {
if (typeof (data[idata]) == "undefined") {
$("#prodesc"+ishow).text("");
$("#proimg"+ishow).attr("src","");
$("#proimg"+ishow).attr("src","genimg/empty.png");
$("#prodiv"+ishow).data("rowid","");
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") {
//Only show products with status=1 (for sell)
$("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
$("#proimg"+ishow).attr("src","genimg/?query=pro&w=55&h=50&id="+data[idata]['id']);
$("#proimg"+ishow).attr("src","genimg/?query=pro&id="+data[idata]['id']);
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
$("#prodiv"+ishow).data("iscat",0);
ishow++; //Next product to show after print data product
}
$("#prowatermark"+ishow).hide();
idata++; //Next data everytime
}
});
@ -189,18 +194,19 @@ function MoreProducts(moreorless){
while (idata < (30*pageproducts)+30) {
if (typeof (data[idata]) == "undefined") {
$("#prodesc"+ishow).text("");
$("#proimg"+ishow).attr("src","");
$("#proimg"+ishow).attr("src","genimg/empty.png");
$("#prodiv"+ishow).data("rowid","");
ishow++; //Next product to show after print data product
}
else if ((data[idata]['status']) == "1") {
//Only show products with status=1 (for sell)
$("#prodesc"+ishow).text(data[parseInt(idata)]['label']);
$("#proimg"+ishow).attr("src","genimg/?query=pro&w=55&h=50&id="+data[idata]['id']);
$("#proimg"+ishow).attr("src","genimg/?query=pro&id="+data[idata]['id']);
$("#prodiv"+ishow).data("rowid",data[idata]['id']);
$("#prodiv"+ishow).data("iscat",0);
ishow++; //Next product to show after print data product
}
$("#prowatermark"+ishow).hide();
idata++; //Next data everytime
}
});
@ -261,12 +267,12 @@ function Search2(){
for (i = 0; i < 30; i++) {
if (typeof (data[i]) == "undefined"){
$("#prodesc"+i).text("");
$("#proimg"+i).attr("src","");
$("#proimg"+i).attr("src","genimg/empty.png");
$("#prodiv"+i).data("rowid","");
continue;
}
$("#prodesc"+i).text(data[parseInt(i)]['label']);
$("#proimg"+i).attr("src","genimg/?query=pro&w=55&h=50&id="+data[i]['rowid']);
$("#proimg"+i).attr("src","genimg/?query=pro&id="+data[i]['rowid']);
$("#prodiv"+i).data("rowid",data[i]['rowid']);
$("#prodiv"+i).data("iscat",0);
}
@ -491,10 +497,11 @@ foreach($menus as $menu) {
{
?>
<div class='wrapper' <?php if ($count==14) echo 'onclick="MoreCategories(\'less\');"'; elseif ($count==15) echo 'onclick="MoreCategories(\'more\');"'; else echo 'onclick="LoadProducts('.$count.');"';?> id='catdiv<?php echo $count;?>'>
<img class='imgwrapper' <?php if ($count==14) echo 'src="img/arrow-prev-top.png"'; if ($count==15) echo 'src="img/arrow-next-top.png"';?> width="98%" id='catimg<?php echo $count;?>'/>
<img class='imgwrapper' <?php if ($count==14) echo 'src="img/arrow-prev-top.png"'; if ($count==15) echo 'src="img/arrow-next-top.png"';?> width="100%" height="85%" id='catimg<?php echo $count;?>'/>
<div class='description'>
<div class='description_content' id='catdesc<?php echo $count;?>'></div>
</div>
<div class="catwatermark" id='catwatermark<?php echo $count;?>'>+</div>
</div>
<?php
$count++;
@ -509,10 +516,11 @@ while ($count<32)
{
?>
<div class='wrapper2' id='prodiv<?php echo $count;?>' <?php if ($count==30) {?> onclick="MoreProducts('less');" <?php } if ($count==31) {?> onclick="MoreProducts('more');" <?php } else echo 'onclick="ClickProduct('.$count.');"';?>>
<img class='imgwrapper' <?php if ($count==30) echo 'src="img/arrow-prev-top.png"'; if ($count==31) echo 'src="img/arrow-next-top.png"';?> width="95%" id='proimg<?php echo $count;?>'/>
<img class='imgwrapper' <?php if ($count==30) echo 'src="img/arrow-prev-top.png"'; if ($count==31) echo 'src="img/arrow-next-top.png"';?> width="100%" height="85%" id='proimg<?php echo $count;?>'/>
<div class='description'>
<div class='description_content' id='prodesc<?php echo $count;?>'></div>
</div>
<div class="catwatermark" id='prowatermark<?php echo $count;?>'>+</div>
</div>
<?php
$count++;