mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
use substitution image if subdef not available
This commit is contained in:
@@ -80,9 +80,9 @@ class PDFRecords extends PDF
|
|||||||
$subdef = $record->get_subdef($this->thumbnailName);
|
$subdef = $record->get_subdef($this->thumbnailName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$subdef->is_physically_present()) {
|
// if (!$subdef->is_physically_present()) {
|
||||||
continue 2;
|
// continue 2;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// check access right on the subdef
|
// check access right on the subdef
|
||||||
if (
|
if (
|
||||||
@@ -93,20 +93,21 @@ class PDFRecords extends PDF
|
|||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
// if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
||||||
continue 2;
|
// continue 2;
|
||||||
}
|
// }
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
continue 2;
|
// use substitution image if the subdef is not available
|
||||||
|
//continue 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::LAYOUT_THUMBNAILLIST:
|
case self::LAYOUT_THUMBNAILLIST:
|
||||||
case self::LAYOUT_THUMBNAILGRID:
|
case self::LAYOUT_THUMBNAILGRID:
|
||||||
try {
|
try {
|
||||||
$subdef = $record->get_subdef($this->thumbnailName);
|
$subdef = $record->get_subdef($this->thumbnailName);
|
||||||
if (!$subdef->is_physically_present()) {
|
// if (!$subdef->is_physically_present()) {
|
||||||
continue 2;
|
// continue 2;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// check access right on the subdef
|
// check access right on the subdef
|
||||||
if (
|
if (
|
||||||
@@ -117,11 +118,12 @@ class PDFRecords extends PDF
|
|||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
// if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
||||||
continue 2;
|
// continue 2;
|
||||||
}
|
// }
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
continue 2;
|
// use substitution image if the subdef is not available
|
||||||
|
//continue 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::LAYOUT_CAPTION:
|
case self::LAYOUT_CAPTION:
|
||||||
@@ -202,30 +204,49 @@ class PDFRecords extends PDF
|
|||||||
$this->pdf->AddPage();
|
$this->pdf->AddPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fimg = null;
|
$fimg = null;
|
||||||
$himg = 0;
|
|
||||||
|
|
||||||
$subdef = $rec->get_subdef($this->previewName);
|
$wimg = $himg = $ImgSize;
|
||||||
|
|
||||||
if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
$subdef = null;
|
||||||
|
|
||||||
|
if ($rec->has_subdef($this->thumbnailName)) {
|
||||||
$subdef = $rec->get_subdef($this->thumbnailName);
|
$subdef = $rec->get_subdef($this->thumbnailName);
|
||||||
// $subdef = $rec->get_thumbnail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fimg = $subdef->getRealPath();
|
if ($subdef == null ||
|
||||||
|
($subdef !== null && ($subdef->get_type() !== \media_subdef::TYPE_IMAGE || !$subdef->is_physically_present()))) {
|
||||||
|
$fimg = sprintf('%s/assets/common/images/icons/substitution/%s.png',
|
||||||
|
$this->app['root.path']."/www",
|
||||||
|
str_replace('/', '_', $rec->getMimeType())
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($size = @getimagesize($fimg)) {
|
||||||
|
$wmm = (int) $size[0] ;
|
||||||
|
$hmm = (int) $size[1] ;
|
||||||
|
if ($wmm > $hmm) {
|
||||||
|
$himg = $wimg * $hmm / $wmm;
|
||||||
|
} else {
|
||||||
|
$wimg = $himg * $wmm / $hmm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$fimg = $subdef->getRealPath();
|
||||||
if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->getBaseId(), \ACL::NOWATERMARK)
|
if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->getBaseId(), \ACL::NOWATERMARK)
|
||||||
&& $subdef->get_type() == \media_subdef::TYPE_IMAGE) {
|
&& $subdef->get_type() == \media_subdef::TYPE_IMAGE) {
|
||||||
$fimg = \recordutils_image::watermark($this->app, $subdef);
|
$fimg = \recordutils_image::watermark($this->app, $subdef);
|
||||||
}
|
}
|
||||||
|
|
||||||
$wimg = $himg = $ImgSize;
|
|
||||||
if ($subdef->get_height() > 0 && $subdef->get_width() > 0) {
|
if ($subdef->get_height() > 0 && $subdef->get_width() > 0) {
|
||||||
if ($subdef->get_width() > $subdef->get_height())
|
if ($subdef->get_width() > $subdef->get_height()) {
|
||||||
$himg = $wimg * $subdef->get_height() / $subdef->get_width();
|
$himg = $wimg * $subdef->get_height() / $subdef->get_width();
|
||||||
else
|
} else {
|
||||||
$wimg = $himg * $subdef->get_width() / $subdef->get_height();
|
$wimg = $himg * $subdef->get_width() / $subdef->get_height();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($fimg) {
|
if ($fimg) {
|
||||||
$x = $lmargin + ($icol * $DiapoW);
|
$x = $lmargin + ($icol * $DiapoW);
|
||||||
@@ -296,15 +317,38 @@ class PDFRecords extends PDF
|
|||||||
|
|
||||||
$ndoc = 0;
|
$ndoc = 0;
|
||||||
foreach ($this->records as $rec) {
|
foreach ($this->records as $rec) {
|
||||||
|
$subdef = null;
|
||||||
|
|
||||||
|
if ($rec->has_subdef($this->thumbnailName)) {
|
||||||
/* @var \record_adapter $rec */
|
/* @var \record_adapter $rec */
|
||||||
$subdef = $rec->get_subdef($this->thumbnailName);
|
$subdef = $rec->get_subdef($this->thumbnailName);
|
||||||
|
}
|
||||||
$fimg = $subdef->getRealPath();
|
|
||||||
|
|
||||||
$wimg = $himg = 50;
|
$wimg = $himg = 50;
|
||||||
|
|
||||||
|
$fimg = null;
|
||||||
|
|
||||||
|
if ($subdef == null ||
|
||||||
|
($subdef !== null && ($subdef->get_type() !== \media_subdef::TYPE_IMAGE || !$subdef->is_physically_present()))) {
|
||||||
|
$fimg = sprintf('%s/assets/common/images/icons/substitution/%s.png',
|
||||||
|
$this->app['root.path']."/www",
|
||||||
|
str_replace('/', '_', $rec->getMimeType())
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($size = @getimagesize($fimg)) {
|
||||||
|
$wi = (int) $size[0] ;
|
||||||
|
$hi = (int) $size[1] ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$fimg = $subdef->getRealPath();
|
||||||
|
$wi = $subdef->get_width();
|
||||||
|
$hi = $subdef->get_height();
|
||||||
|
}
|
||||||
|
|
||||||
// 1px = 3.77952 mm
|
// 1px = 3.77952 mm
|
||||||
$finalWidth = round($subdef->get_width() / 3.779528, 2);
|
$finalWidth = round($wi / 3.779528, 2);
|
||||||
$finalHeight = round($subdef->get_height() / 3.779528, 2);
|
$finalHeight = round($hi / 3.779528, 2);
|
||||||
|
|
||||||
$aspectH = $finalWidth/$finalHeight;
|
$aspectH = $finalWidth/$finalHeight;
|
||||||
$aspectW = $finalHeight/$finalWidth;
|
$aspectW = $finalHeight/$finalWidth;
|
||||||
|
|
||||||
@@ -636,24 +680,41 @@ class PDFRecords extends PDF
|
|||||||
|
|
||||||
$y = $this->pdf->GetY() + 5;
|
$y = $this->pdf->GetY() + 5;
|
||||||
|
|
||||||
|
$subdef = null;
|
||||||
|
|
||||||
|
if ($rec->has_subdef($this->previewName)) {
|
||||||
|
/* @var \record_adapter $rec */
|
||||||
$subdef = $rec->get_subdef($this->previewName);
|
$subdef = $rec->get_subdef($this->previewName);
|
||||||
|
|
||||||
if ($subdef->get_type() !== \media_subdef::TYPE_IMAGE) {
|
|
||||||
$subdef = $rec->get_subdef($this->thumbnailName);
|
|
||||||
// $subdef = $rec->get_thumbnail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$f = $subdef->getRealPath();
|
|
||||||
|
|
||||||
if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->getBaseId(), \ACL::NOWATERMARK)
|
|
||||||
&& $subdef->get_type() == \media_subdef::TYPE_IMAGE)
|
|
||||||
$f = \recordutils_image::watermark($this->app, $subdef);
|
|
||||||
|
|
||||||
// original height / original width x new width = new height
|
// original height / original width x new width = new height
|
||||||
$wimg = $himg = 150; // preview dans un carre de 150 mm
|
$wimg = $himg = 150; // preview dans un carre de 150 mm
|
||||||
|
|
||||||
|
if ($subdef == null ||
|
||||||
|
($subdef !== null && ($subdef->get_type() !== \media_subdef::TYPE_IMAGE || !$subdef->is_physically_present()))) {
|
||||||
|
$f = sprintf('%s/assets/common/images/icons/substitution/%s.png',
|
||||||
|
$this->app['root.path']."/www",
|
||||||
|
str_replace('/', '_', $rec->getMimeType())
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($size = @getimagesize($f)) {
|
||||||
|
$wi = (int) $size[0] ;
|
||||||
|
$hi = (int) $size[1] ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$f = $subdef->getRealPath();
|
||||||
|
|
||||||
|
if (!$this->app->getAclForUser($this->app->getAuthenticatedUser())->has_right_on_base($rec->getBaseId(), \ACL::NOWATERMARK)
|
||||||
|
&& $subdef->get_type() == \media_subdef::TYPE_IMAGE) {
|
||||||
|
$f = \recordutils_image::watermark($this->app, $subdef);
|
||||||
|
}
|
||||||
|
$wi = $subdef->get_width();
|
||||||
|
$hi = $subdef->get_height();
|
||||||
|
}
|
||||||
|
|
||||||
// 1px = 3.77952 mm
|
// 1px = 3.77952 mm
|
||||||
$finalWidth = round($subdef->get_width() / 3.779528, 2);
|
$finalWidth = round($wi / 3.779528, 2);
|
||||||
$finalHeight = round($subdef->get_height() / 3.779528, 2);
|
$finalHeight = round($hi / 3.779528, 2);
|
||||||
$aspectH = $finalWidth/$finalHeight;
|
$aspectH = $finalWidth/$finalHeight;
|
||||||
$aspectW = $finalHeight/$finalWidth;
|
$aspectW = $finalHeight/$finalWidth;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user