Skip to content

Commit

Permalink
WIP DO NOT REVIEW/MERGE
Browse files Browse the repository at this point in the history
add `set-dpi` module
fix bad subdef settings import
  • Loading branch information
jygaulier committed Dec 23, 2024
1 parent 4b6a86d commit 52d908d
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 9 deletions.
31 changes: 23 additions & 8 deletions databox/indexer/src/handlers/phraseanet/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,22 +691,32 @@ function translateDocumentSettings_toPdf(): object {

function translateImageSettings(sd: PhraseanetSubdefStruct): object {
// todo: extension ?
const size = sd.options['size'] ?? 100;
const size = sd.options['size'];

return {
transformations: [
{
module: 'imagine',
options: {
filters: [
{
thumbnail: {
size: [size, size],
},
filters: {
auto_rotate: {},
background_fill: {
color: '#FFFFFF',
opacity: 100,
},
],
thumbnail: {
size: [size, size],
mode: 'inset',
},
},
},
},
{
module: 'set_dpi',
options: {
dpi: sd.options['resolution'],
}
}
],
};
}
Expand Down Expand Up @@ -907,7 +917,12 @@ function jsToYaml(a: any, depth: number): string {
if (k[0] === '#') {
t += `\n${tab}# ${a[k]}`;
} else {
t += `\n${tab}${k}:${jsToYaml(a[k], depth + 1)}`;
// console.log("------- ", k, a[k]);
if((a[k] instanceof Array || typeof a[k] === 'object') && Object.keys(a[k]).length === 0) {
t += `\n${tab}${k}: ~`;
} else {
t += `\n${tab}${k}:${jsToYaml(a[k], depth + 1)}`;
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ services:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

Alchemy\RenditionFactory\Transformer\Image\SetDpiTransformerModule:
tags:
- { name: !php/const Alchemy\RenditionFactory\Transformer\TransformerModuleInterface::TAG }

# Output "formats"
Alchemy\RenditionFactory\Transformer\Video\Format\JpegFormat:
tags:
Expand Down
21 changes: 20 additions & 1 deletion lib/php/rendition-factory/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
"test": "./vendor/bin/phpunit",
"cs": "vendor/bin/php-cs-fixer fix"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/alchemy-fr/PHPExiftool"
},
{
"type": "package",
"package": {
"name": "exiftool/exiftool",
"version": "12",
"source": {
"url": "https://github.com/exiftool/exiftool",
"type": "git",
"reference": "12.42"
}
}
}
],
"require": {
"php": "^8.3",
"ext-imagick": "*",
Expand All @@ -31,7 +49,8 @@
"liip/imagine-bundle": "^2.13",
"symfony/http-client": "^6.4.11",
"php-ffmpeg/php-ffmpeg": "^1.2",
"spatie/pdf-to-image": "^3.1"
"spatie/pdf-to-image": "^3.1",
"alchemy/phpexiftool": "^4.0.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.17",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Alchemy\RenditionFactory\Transformer\Image;

use Alchemy\RenditionFactory\Context\TransformationContextInterface;
use Alchemy\RenditionFactory\DTO\FamilyEnum;
use Alchemy\RenditionFactory\DTO\InputFileInterface;
use Alchemy\RenditionFactory\DTO\OutputFile;
use Alchemy\RenditionFactory\DTO\OutputFileInterface;
use Alchemy\RenditionFactory\Transformer\Documentation;
use Alchemy\RenditionFactory\Transformer\TransformerConfigHelper;
use Alchemy\RenditionFactory\Transformer\TransformerModuleInterface;
// use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Exiftool;
use PHPExiftool\Writer;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;


final readonly class SetDpiTransformerModule implements TransformerModuleInterface
{
public function __construct(private LoggerInterface $logger) {
}

public static function getName(): string
{
return 'set_dpi';
}

public function getDocumentation(): Documentation
{
$treeBuilder = TransformerConfigHelper::createBaseTree(self::getName());
$this->buildConfiguration($treeBuilder->getRootNode()->children());

return new Documentation(
$treeBuilder,
<<<HEADER
Change the dpi metadata of an image (no resampling).
HEADER
);
}

public function buildConfiguration(NodeBuilder $builder): void
{
// @formatter:off
$builder
->arrayNode('options')
->children()
->IntegerNode('dpi')
->isRequired()
->example('72')
->end()
->end()
->end()
;
// @formatter:on
}

public function transform(InputFileInterface $inputFile, array $options, TransformationContextInterface $context): OutputFileInterface
{
if($inputFile->getFamily() !== FamilyEnum::Image) {
throw new \InvalidArgumentException('Input file must be an image');
}
$dpi = $options['dpi'];
$this->logger->info(sprintf('Setting DPI to %s', $dpi));
$writer = Writer::create(
new Exiftool($this->logger)
);
$writer->write(
$inputFile->getPath(),
new MetadataBag([
// new Metadata([
// 'dpi' => $dpi,
// ]),
]),
null,
[$dpi, $dpi]
);

return new OutputFile(
$inputFile->getPath(),
$inputFile->getType(),
FamilyEnum::Image,
false // TODO implement projection
);
}
}

0 comments on commit 52d908d

Please sign in to comment.