Skip to content

Commit

Permalink
modified: Plugin.php
Browse files Browse the repository at this point in the history
	modified:   classes/MediaExtensions.php
  • Loading branch information
Helmut Kaufmann committed Feb 12, 2022
1 parent 59ae537 commit ad0db1a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
44 changes: 22 additions & 22 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ public function register()
* @return array
*/
public function boot()
{
{
Image::configure(array(
'driver' => 'imagick'
));

Event::listen('system.resizer.processResize', function ($resizer, $tempPath)
{

EventLog::add("TEMP PATH: $tempPath");
// Get the configuration options the user has sumitted
$config = $resizer->getConfig();
$options = array_get($config, 'options', []);
Expand Down Expand Up @@ -83,9 +82,9 @@ public function boot()
if (!$filters)
{ // End here if there are no filters to apply
\Winter\Storm\Database\Attach\Resizer::open($tempPath)->resize($width, $height, $options)->save($newPath);
if ($newPath != $tempPath)
File::move($newPath, $tempPath);
if ($newPath != $tempPath)
File::move($newPath, $tempPath);

// Prevent any other resizing replacer logic from running
return true;
}
Expand All @@ -104,13 +103,13 @@ public function boot()
if (!$filters)
{ // End here if there are no filters to apply
$image = Image::make($tempPath)->resize($width, $height)->save($newPath, $quality, $extension);
if ($newPath != $tempPath)
if ($newPath != $tempPath)
File::move($newPath, $tempPath);

// Prevent any other resizing replacer logic from running
return true;
}
else
else
{
// Resize
$image = Image::make($tempPath)->resize($width, $height);
Expand Down Expand Up @@ -167,11 +166,11 @@ public function boot()
break;

/* Not working - review needed
case 'invert':
$image=$image->invert();
break;
*/

case 'limitColors':
Expand Down Expand Up @@ -211,17 +210,17 @@ public function boot()
elseif (strcmp($filters, "")) $image = eval("{ return \$image->" . $filters . "; }");

$image->save($newPath, $quality, $extension);
if ($newPath != $tempPath)
if ($newPath != $tempPath)
File::move($newPath, $tempPath);

// Prevent any other resizing replacer logic from running
return true;

});
}

}



/**
* Registers any front-end components implemented in this plugin.
Expand All @@ -231,7 +230,7 @@ public function boot()
public function registerComponents()
{
return []; // Remove this line to activate

}

/**
Expand All @@ -242,7 +241,7 @@ public function registerComponents()
public function registerPermissions()
{
return []; // Remove this line to activate

}

/**
Expand All @@ -253,13 +252,14 @@ public function registerPermissions()
public function registerNavigation()
{
return []; // Remove this line to activate

}

public function registerMarkupTags()
{
return ['filters' => ['iresize' => [MediaExtensions::class , 'iresize'], 'ifilter' => [MediaExtensions::class , 'iresize']

], 'functions' => ['exif' => [MediaExtensions::class , 'exif'], 'iptc' => [MediaExtensions::class , 'iptc'], ], ];
return [
'filters' => ['iresize' => [MediaExtensions::class , 'iresize'], 'ifilter' => [MediaExtensions::class , 'iresize'], ],
'functions' => ['exif' => [MediaExtensions::class , 'exif'], 'iptc' => [MediaExtensions::class , 'iptc'], ]
];
}
}
44 changes: 22 additions & 22 deletions classes/MediaExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class MediaExtensions extends \Backend\Classes\Controller
'imageTypes' => [
'image/webp' => [
'extension' => 'webp',
'quality' => 50,
'quality' => 60,
],
'image/jpg' => [
'extension' => 'jpg',
'quality' => 60,
'quality' => 70,
],
'image/jpeg' => [
'extension' => 'jpeg',
'quality' => 60,
'quality' => 70,
],
'image/gif' => [
'extension' => 'gif',
Expand All @@ -50,63 +50,63 @@ public static function acceptsFormat($type)

return in_array($type, $acceptableTypes) || in_array("image/$type", $acceptableTypes);
}
public static function iresize($image, $width=null, $height=null, $filters=null, $extension=null, $quality=null)


public static function iresize($image, $width=null, $height=null, $filters=null, $extension=null, $quality=null)
{
// Check if the file exists
$path = public_path(parse_url($image, PHP_URL_PATH));
if (!File::exists($path)) {
return $image;
}

// Uxtension must be all lower case
if ($extension)
$extension = strtolower($extension);

// Use the explicitly spcifie format or provide the best available if no format has been specified
foreach (static::$defaultOptions['imageTypes'] as $type => $typeOptions) {

$ext = array_get($typeOptions, 'extension');

if (($extension && !strcmp($ext, $extension)) || (!$extension && static::acceptsFormat($type))) {

if (!$quality)
$quality = array_get($typeOptions, 'quality', 90);
$publicPath = File::localToPublic($path);
$resizerPath = ImageResizer::filterGetUrl($publicPath, $width, $height, ['extension' => $ext, 'quality'=> $quality, 'filters' => $filters ]);

$url = urldecode(urldecode($resizerPath));
$resizedImagePath = base_path(substr($url, strpos($url, "//")));

/*
if (is_file($resizedImagePath) && ( filectime($resizedImagePath) < filectime(base_path() . $image))) {
// The image is newer than the resiuzed one, unlink the resized, so it gets re-generated.
// EventLog::add("isresize - Resized image removed as there is a new original in " . __FILE__);
unlink($resizedImagePath);
}
*/

return $resizerPath;

}
}

EventLog::add("Could not resize image, unknown format $extension in " . __FILE__);
return $image;
}
public static function exif($image, $type=null)

public static function exif($image, $type=null)
{
if (!$type)
return $data = Image::make(base_path(). $image)->exif();
else
return Image::make($image)->exif($type);
}
public static function iptc($image, $type=null)

public static function iptc($image, $type=null)
{
if (!$type)
return $data = Image::make(base_path().$image)->iptc();
Expand Down

0 comments on commit ad0db1a

Please sign in to comment.