Skip to content

Commit

Permalink
Configurable media type options
Browse files Browse the repository at this point in the history
This change introduces a new configuration option which allows to force the import to use
the high-resolution original instead of a preview version.

By default, JPG and PNG are now using the preview generated by Pixxio instead of the original
file. This can improve import speed with very large photos and solve memory problems caused
by the resizing process.
  • Loading branch information
robertlemke committed Nov 21, 2018
1 parent 359df93 commit 2553921
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Classes/AssetSource/PixxioAssetProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ final class PixxioAssetProxy implements AssetProxyInterface, HasRemoteOriginalIn
*/
static public function fromJsonObject(\stdClass $jsonObject, PixxioAssetSource $assetSource)
{
$usePixxioThumbnailAsOriginal = !in_array($jsonObject->fileType, ['JPG', 'PNG', 'SVG', 'PDF']);

$assetSourceOptions = $assetSource->getAssetSourceOptions();
$pixxioOriginalMediaType = MediaTypes::getMediaTypeFromFilename('foo.' . strtolower($jsonObject->fileType));;
$usePixxioThumbnailAsOriginal = (!isset($assetSourceOptions['mediaTypes'][$pixxioOriginalMediaType]) || $assetSourceOptions['mediaTypes'][$pixxioOriginalMediaType]['usePixxioThumbnailAsOriginal'] === false);
$modifiedFileType = $usePixxioThumbnailAsOriginal ? 'jpg' : strtolower($jsonObject->fileType);

$assetProxy = new static();
Expand All @@ -121,7 +122,8 @@ static public function fromJsonObject(\stdClass $jsonObject, PixxioAssetSource $
$assetProxy->fileSize = $jsonObject->fileSize;
$assetProxy->mediaType = MediaTypes::getMediaTypeFromFilename('foo.' . $modifiedFileType);

$assetProxy->iptcProperties['Title'] = $jsonObject->subject ?? '';
# $assetProxy->iptcProperties['Title'] = $jsonObject->subject ?? '';
$assetProxy->iptcProperties['Title'] = $usePixxioThumbnailAsOriginal ? 'YES' : 'NO';
$assetProxy->iptcProperties['CaptionAbstract'] = $jsonObject->description ?? '';

$assetProxy->widthInPixels = $jsonObject->imageWidth ?? null;
Expand Down
3 changes: 3 additions & 0 deletions Classes/AssetSource/PixxioAssetProxyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Flownative\Pixxio\Exception\AssetNotFoundException;
use Flownative\Pixxio\Exception\AuthenticationFailedException;
use Flownative\Pixxio\Exception\ConnectionException;
use Flownative\Pixxio\Exception\MissingClientSecretException;
use Neos\Cache\Frontend\VariableFrontend;
use Neos\Media\Domain\Model\AssetSource\AssetNotFoundExceptionInterface;
Expand Down Expand Up @@ -67,6 +68,8 @@ public function __construct(PixxioAssetSource $assetSource)
* @throws MissingClientSecretException
* @throws AuthenticationFailedException
* @throws AssetNotFoundException
* @throws ConnectionException
* @throws \Neos\Cache\Exception
*/
public function getAssetProxy(string $identifier): AssetProxyInterface
{
Expand Down
27 changes: 27 additions & 0 deletions Classes/AssetSource/PixxioAssetSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Neos\Flow\Security\Context;
use Neos\Media\Domain\Model\AssetSource\AssetProxyRepositoryInterface;
use Neos\Media\Domain\Model\AssetSource\AssetSourceInterface;
use Neos\Utility\MediaTypes;

/**
*
Expand Down Expand Up @@ -78,6 +79,11 @@ class PixxioAssetSource implements AssetSourceInterface
*/
private $pixxioClient;

/**
* @var array
*/
private $assetSourceOptions;

/**
* @param string $assetSourceIdentifier
* @param array $assetSourceOptions
Expand All @@ -87,7 +93,10 @@ public function __construct(string $assetSourceIdentifier, array $assetSourceOpt
if (preg_match('/^[a-z][a-z0-9-]{0,62}[a-z]$/', $assetSourceIdentifier) !== 1) {
throw new \InvalidArgumentException(sprintf('Invalid asset source identifier "%s". The identifier must match /^[a-z][a-z0-9-]{0,62}[a-z]$/', $assetSourceIdentifier), 1525790890);
}

$this->assetSourceIdentifier = $assetSourceIdentifier;
$this->assetSourceOptions = $assetSourceOptions;

foreach ($assetSourceOptions as $optionName => $optionValue) {
switch ($optionName) {
case 'apiEndpointUri':
Expand All @@ -106,6 +115,16 @@ public function __construct(string $assetSourceIdentifier, array $assetSourceOpt
}
$this->sharedRefreshToken = $optionValue;
break;
case 'mediaTypes':
if (!is_array($optionValue)) {
throw new \InvalidArgumentException(sprintf('Invalid media types specified for Pixx.io asset source %s', $assetSourceIdentifier), 1542809628);
}
foreach ($optionValue as $mediaType => $mediaTypeOptions) {
if (MediaTypes::getFilenameExtensionsFromMediaType($mediaType) === []) {
throw new \InvalidArgumentException(sprintf('Unknown media type "%s" specified for Pixx.io asset source %s', $mediaType, $assetSourceIdentifier), 1542809775);
}
}
break;
default:
throw new \InvalidArgumentException(sprintf('Unknown asset source option "%s" specified for Pixx.io asset source "%s". Please check your settings.', $optionName, $assetSourceIdentifier), 1525790910);
}
Expand Down Expand Up @@ -158,6 +177,14 @@ public function isReadOnly(): bool
return true;
}

/**
* @return array
*/
public function getAssetSourceOptions(): array
{
return $this->assetSourceOptions;
}

/**
* @return PixxioClient
* @throws MissingClientSecretException
Expand Down
6 changes: 6 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Neos:
# this Neos installation.
# sharedRefreshToken: ''

# Additional configuration for specific media types
mediaTypes:
'image/svg+xml':
usePixxioThumbnailAsOriginal: true
'application/pdf':
usePixxioThumbnailAsOriginal: true
Neos:
modules:
management:
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ into the form found in the backend module and store it along with your Neos user
When everything works out fine, Neos will report that the connection was successful (and if not, you'll see an error
message with further details).
## Additional configuration options
During import, Neos tries to use a medium-sized version of the original instead of the high resolution file uploaded to
pixx.io. This greatly improves import speed and produces good results in most cases. Furthermore, this way some formats,
like Adobe Photoshop, can be used seamlessly in Neos without the need to prior converting them into a web-compatible image
format.
It is possible though, to configure this plugin to always use the high-res original for import. By default, formats like SVG or PDF
are imported this way. You can add more types through the similar entries like in the following settings:
```yaml
Neos:
Media:
assetSources:
'flownative-pixxio':
assetSource: 'Flownative\Pixxio\AssetSource\PixxioAssetSource'
assetSourceOptions:
mediaTypes:
'image/svg+xml':
usePixxioThumbnailAsOriginal: true
'application/pdf':
usePixxioThumbnailAsOriginal: true
```
## Cleaning up unused assets
Whenever a pixx.io asset is used in Neos, the media file will be copied automatically to the internal Neos asset
Expand Down

0 comments on commit 2553921

Please sign in to comment.