Skip to content

Commit

Permalink
replace PHPImageWorkshop with Intervention/Image
Browse files Browse the repository at this point in the history
doc typo fix
  • Loading branch information
stefan committed May 8, 2024
1 parent 698038e commit b16818a
Show file tree
Hide file tree
Showing 349 changed files with 18,274 additions and 88 deletions.
9 changes: 9 additions & 0 deletions inc/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,13 @@
define('FPCM_COMPONENT_PHOTOSWIPE', true);
}

if (!defined('FPCM_IMAGE_PROCESSOR_NEW')) {

/**
* Enable PhotoSwipe Lightbox
* @since 5.2.0-rc2
*/
define('FPCM_IMAGE_PROCESSOR_NEW', true);
}


71 changes: 30 additions & 41 deletions inc/model/files/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Image file objekt
*
*
* @package fpcm\model\files
* @author Stefan Seehafer <sea75300@yahoo.de>
* @copyright (c) 2011-2022, Stefan Seehafer
Expand Down Expand Up @@ -97,7 +97,7 @@ class image
* @var array
*/
protected $dbParams = ['userid', 'filename', 'filetime', 'filesize', 'alttext'];

/**
* Konstruktor
* @param string $filename file name including sub path
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getThumbnail()
if (count($fnArr) == 2) {
return $fnArr[0].'/thumbs/'.$fnArr[1];
}

return 'thumbs/' . $this->filename;
}

Expand Down Expand Up @@ -274,7 +274,7 @@ public function getMimetype()
public function getIptcStr() {
return $this->iptcStr;
}

/**
* Datensatz-ID setzen
* @param int $id
Expand Down Expand Up @@ -359,7 +359,7 @@ public function delete()
if (!$this->isValidDataFolder('', \fpcm\classes\dirs::DATA_UPLOADS)) {
return false;
}

parent::delete();
if ($this->hasFileManageThumbnail()) {
unlink($this->getFileManagerThumbnail());
Expand Down Expand Up @@ -412,7 +412,7 @@ public function rename($newname, $userId = false)

return true;
}

/**
* Check if image exists
* @param type $dbOnly
Expand All @@ -423,7 +423,7 @@ public function exists($dbOnly = false)
if (!$this->filename) {
return false;
}

$fileExists = $this->existsFolder();
if ($dbOnly) {
return (bool) $this->isIndexed;
Expand Down Expand Up @@ -452,27 +452,18 @@ public function existsFolder()
*/
public function createThumbnail()
{
include_once \fpcm\classes\loader::libGetFilePath('PHPImageWorkshop');

try {
$phpImgWsp = \PHPImageWorkshop\ImageWorkshop::initFromPath($this->getFullpath());
$phpImgWsp->cropToAspectRatio(
\PHPImageWorkshop\Core\ImageWorkshopLayer::UNIT_PIXEL,
$this->config->file_thumb_size,
$this->config->file_thumb_size,
0, 0, 'MM'
);

$fullThumbPath = $this->getThumbnailFull();
$phpImgWsp->resizeInPixel($this->config->file_thumb_size, $this->config->file_thumb_size);
$phpImgWsp->save(dirname($fullThumbPath), basename($fullThumbPath), true, null, 85);
} catch (\ErrorException $exc) {
trigger_error('Error while creating file thumbnail '.$this->getThumbnail().PHP_EOL.$exc->getMessage());
$fullPath = $this->getThumbnailFull();

$proc = new thumbnailCreator($this->getFullpath(), $fullPath);

$fn = thumbnailCreator::getFunctionName();

if (!$proc->{$fn}()) {
return false;
}
}

$this->events->trigger('image\thumbnailCreate', $this)->getData();
if (!file_exists($fullThumbPath)) {
if (!file_exists($fullPath)) {
trigger_error('Unable to create thumbnail: ' . $this->getThumbnail());
return false;
}
Expand All @@ -488,11 +479,11 @@ public function createThumbnail()
public function addUploadFolder() : bool
{
$this->fullpath = ops::getUploadPath($this->filename, $this->config->file_subfolders);

if (!file_exists(dirname($this->fullpath))) {
mkdir(dirname($this->fullpath));
}

return true;
}

Expand All @@ -519,10 +510,10 @@ protected function init($initDB)
{
if ($initDB) {
$dbData = $this->dbcon->selectFetch((new \fpcm\model\dbal\selectParams($this->table))->setWhere('filename = ?')->setParams([$this->filename]));
if (!$dbData) {
if (!$dbData) {
$this->isIndexed = false;
}
else {
else {
foreach ($dbData as $key => $value) {
$this->$key = $value;
}
Expand All @@ -531,11 +522,11 @@ protected function init($initDB)
}
}
else {
$this->isIndexed = false;
$this->isIndexed = false;
}

if (!parent::exists()) {
return true;
return true;
}

$this->extension = self::retrieveFileExtension($this->fullpath);
Expand Down Expand Up @@ -630,14 +621,14 @@ protected function splitFilename(string $filename) : string
* reads IPTC data from file
* @param array $info
* @return bool
* @since 4.2.1
* @since 4.2.1
*/
public function parseIptc($info)
{
if ($this->iptcStr === null || trim($this->iptcStr)) {
return true;
}

if (!function_exists('iptcparse') || !is_array($info) || !count($info)) {
return false;
}
Expand All @@ -650,12 +641,12 @@ public function parseIptc($info)
return [];
}

foreach (array_keys($iptc) as $s) {
foreach (array_keys($iptc) as $s) {
$c = count ($iptc[$s]);
for ($i=0; $i <$c; $i++) {
$this->iptcStr[$s] = $iptc[$s][$i];
}
}
}

$this->iptcStr = array_intersect_key($this->iptcStr, ['2#080' => 1, '2#110' => 1, '2#116' => 1]);

Expand Down Expand Up @@ -683,7 +674,7 @@ public function getPropertiesArray(string $userName) : array
'fileresy' => $this->getHeight(),
'filehash' => $this->getFileHash(),
'filemime' => $this->getMimetype(),
'credits' => $this->getIptcStr()
'credits' => $this->getIptcStr()
];
}

Expand All @@ -693,7 +684,7 @@ public function getPropertiesArray(string $userName) : array
* @since 5.0.0-a1
*/
public static function getCropperFilename(string &$filename)
{
{
$repl = [
'{{filename}}' => self::retrieveFileName($filename),
'{{date}}' => date('Y-m-d'),
Expand All @@ -702,8 +693,8 @@ public static function getCropperFilename(string &$filename)
'{{userid}}' => \fpcm\classes\loader::getObject('\fpcm\model\system\session')->getUserId(),
'{{random}}' => mt_rand()
];
$pattern = \fpcm\classes\loader::getObject('\fpcm\model\system\config')->file_cropper_name;

$pattern = \fpcm\classes\loader::getObject('\fpcm\model\system\config')->file_cropper_name;
if (!trim($pattern)) {
$pattern = '{{filename}}_cropped_{{date}}';
}
Expand Down Expand Up @@ -738,5 +729,3 @@ public static function isValidType(string $ext, string $type, array $map = []) :
}

}

?>
54 changes: 24 additions & 30 deletions inc/model/files/imagelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getDatabaseListByCondition(search $conditions)
$where = [];
$valueParams = [];
$combination = '';

if ($conditions->isMultiple()) {
$this->assignMultipleSearchParams($conditions, $where, $valueParams, $combination);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public function getDatabaseCountByCondition(search $conditions)
* Aktualisiert Dateiindex in Datenbank
* @param int $userId
*/

/**
* Updates file index
* @param int $userId
Expand All @@ -177,15 +177,15 @@ public function updateFileIndex($userId)
if (!$fsIdx || !count($fsIdx)) {
return true;
}

if ($userId === '' || $userId === null) {
$userId = 0;
}

array_walk($fsIdx, [$this, 'removeBasePath']);

$fsIdx = array_flip($fsIdx);

$notInDb = array_diff_key($fsIdx, $dbIdx);
$notInFs = array_diff_key($dbIdx, $fsIdx);

Expand Down Expand Up @@ -254,10 +254,10 @@ private function addToIndex(string $file) : bool
trigger_error("Unable to save image \"{$image->getFullpath()}\" to database, file is already indexed.");
return false;
}

if (!$res) {
trigger_error("Unable to save image \"{$image->getFullpath()}\" to database, due to unknows reason.");
return false;
return false;
}

return true;
Expand All @@ -272,7 +272,7 @@ public function getDatabaseFileCount()
{
return $this->dbcon->count($this->table);
}

/**
* Creates file manager thumbnails
* @param array|null $folderFiles
Expand All @@ -281,7 +281,8 @@ public function getDatabaseFileCount()
*/
public function createFilemanagerThumbs(?array $folderFiles = null, ?bool $forceAll = null) : bool
{
include_once \fpcm\classes\loader::libGetFilePath('PHPImageWorkshop');
$fn = thumbnailCreator::getFunctionName();

if ($folderFiles === null) {
$folderFiles = $this->getFolderList();
}
Expand All @@ -292,7 +293,7 @@ public function createFilemanagerThumbs(?array $folderFiles = null, ?bool $force

$filesizeLimit = \fpcm\classes\baseconfig::memoryLimit(true) * 0.025;
$folderFiles = array_filter($folderFiles, function ($folderFile) use ($filesizeLimit) {

if (filesize($folderFile) >= $filesizeLimit) {
$msgPath = ops::removeBaseDir($folderFile);
fpcmLogSystem("Skip filemanager thumbnail generation for {$msgPath} because of image dimension. You may reduce file size?");
Expand All @@ -305,38 +306,31 @@ public function createFilemanagerThumbs(?array $folderFiles = null, ?bool $force
fpcmLogSystem("Skip filemanager thumbnail generation for {$msgPath}, \"".$ext."\" is no supported. You may use another image type?");
return false;
}

return true;
});

if (!count($folderFiles)) {
return false;
}

$thumbSize = $this->config->file_thumb_size;

foreach ($folderFiles as $folderFile) {

$imgPath = $folderFile;
$this->removeBasePath($imgPath);

$image = new \fpcm\model\files\image($imgPath);

if ($image->hasFileManageThumbnail() && !$forceAll) {
$image = null;
$phpImgWsp = null;
continue;
}

try {
$phpImgWsp = \PHPImageWorkshop\ImageWorkshop::initFromPath($folderFile);
$phpImgWsp->cropToAspectRatio(
\PHPImageWorkshop\Core\ImageWorkshopLayer::UNIT_PIXEL,
$thumbSize, $thumbSize, 0, 0, 'MM'
);

$phpImgWsp->resizeInPixel($thumbSize, $thumbSize);
$phpImgWsp->save(dirname($image->getFileManagerThumbnail()), basename($image->getFileManagerThumbnail()));
} catch (\Exception $exc) {

$proc = new thumbnailCreator($folderFile, $image->getFileManagerThumbnail());
if (!$proc->{$fn}()) {
trigger_error('Error while creating filemanager thumbnail '.$image->getFileManagerThumbnail().PHP_EOL.$exc->getMessage());
continue;
}
Expand All @@ -346,7 +340,7 @@ public function createFilemanagerThumbs(?array $folderFiles = null, ?bool $force
}

$image = null;
$phpImgWsp = null;
$proc = null;
}

return true;
Expand Down Expand Up @@ -392,7 +386,7 @@ private function assignSearchParams(search $conditions, array &$where, array &$v
$where[] = "filetime <= :filetimet";
$valueParams[':filetimet'] = $conditions->dateto;
}

$combination = $conditions->combination ? $conditions->combination : 'AND';
return true;
}
Expand Down Expand Up @@ -458,7 +452,7 @@ public function getSearchQuery(): \fpcm\model\dbal\selectParams
*/
public function getElementLink(mixed $filename): string
{
$tmp = new image($filename, false);
$tmp = new image($filename, false);
return $tmp->getImageUrl();
}

Expand Down Expand Up @@ -490,15 +484,15 @@ private function getSearchQueryObj(): \fpcm\model\dbal\selectParams
public function prepareText(string $text): string
{
list($name, $alttext, $date) = explode(';', $text);

$name = basename($name);

return sprintf(
'%s%s<br><span class="fpcm ui-font-small text-secondary">%s</span>',
new \fpcm\view\helper\escape($alttext ? $alttext : $name),
new \fpcm\view\helper\escape($alttext ? ' ('.$name.')' : ''),
new \fpcm\view\helper\dateText($date)
);
);
}

}
Expand Down

0 comments on commit b16818a

Please sign in to comment.