Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d61848f
Add support for HEIC/HEIF to JPEG conversion
NikolayBalkandzhiyski Dec 18, 2025
ec8755f
Normalize image extension input in ConvertableImageType enum
NikolayBalkandzhiyski Dec 18, 2025
6cdac9d
-Add SPDX license headers to multiple files and normalize variable names
NikolayBalkandzhiyski Dec 18, 2025
0c7cc69
Add migration to change 'title' column type to TEXT in photos table b…
NikolayBalkandzhiyski Dec 22, 2025
14ccea0
Update migration to change 'title' column type from TEXT to VARCHAR(1…
NikolayBalkandzhiyski Jan 6, 2026
70e7d01
Refactor migration to change 'title' column type from VARCHAR(1000) t…
NikolayBalkandzhiyski Jan 6, 2026
74d7567
Enhance migration for 'title' column in photos table by adding index …
NikolayBalkandzhiyski Jan 6, 2026
303ee3f
Add support for HEIC to JPEG conversion using maestroerror/php-heic-t…
NikolayBalkandzhiyski Jan 6, 2026
30e0553
Improve error handling in HEIC to JPEG conversion by adding nested ex…
NikolayBalkandzhiyski Jan 6, 2026
f24e705
added comment
NikolayBalkandzhiyski Jan 6, 2026
7e0b9f6
Update ConvertMediaFileInterface to support both Imagick and HeicToJp…
NikolayBalkandzhiyski Jan 6, 2026
25cfca0
Merge remote-tracking branch 'upstream/master' into feature/#298-HEIC…
NikolayBalkandzhiyski Jan 6, 2026
584deef
chore: Update HEIC to JPEG conversion logic and improve error handling
NikolayBalkandzhiyski Jan 6, 2026
3fad818
chore: Update composer.lock and add new dependencies
NikolayBalkandzhiyski Jan 6, 2026
a64fbc4
Improve error messages in HEIF to JPEG conversion and update migratio…
NikolayBalkandzhiyski Jan 6, 2026
142f145
Fix formatting of SPDX license comment in migration file for photos t…
NikolayBalkandzhiyski Jan 6, 2026
f8f91e4
chore: update copyright year in multiple files to 2026
NikolayBalkandzhiyski Jan 6, 2026
c2d5a1f
Refactor ImageTypeFactory and ConvertUnsupportedMedia for improved er…
NikolayBalkandzhiyski Jan 7, 2026
3213960
Update index creation logic for title column in photos table based on…
NikolayBalkandzhiyski Jan 7, 2026
b3dbcf1
Merge branch 'master' into feature/#298-HEIC-HEIF
ildyria Jan 13, 2026
105c7cd
simplify
ildyria Jan 13, 2026
1e74f8c
Merge branch 'master' into feature/#298-HEIC-HEIF
ildyria Jan 14, 2026
192e567
simplify
ildyria Jan 14, 2026
80e847e
Wrap up
ildyria Jan 14, 2026
e7b83f6
improve indexing
ildyria Jan 14, 2026
9b5c877
Formatting
ildyria Jan 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/Actions/Photo/Convert/HeifToJpeg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Actions\Photo\Convert;

use App\Contracts\PhotoCreate\PhotoConverter;
use App\Exceptions\CannotConvertMediaFileException;
use App\Image\Files\NativeLocalFile;
use App\Image\Files\TemporaryJobFile;
use App\Repositories\ConfigManager;

class HeifToJpeg implements PhotoConverter
{
public function __construct(
private ConfigManager $config_manager,
) {
}

/**
* @throws \Exception
*/
public function handle(NativeLocalFile $tmp_file): TemporaryJobFile
{
if ($this->config_manager->hasImagick() === false) {
throw new CannotConvertMediaFileException('Imagick is not available.');
}

$path = $tmp_file->getRealPath();
$pathinfo = pathinfo($path);
$file_name = $pathinfo['filename'];
$new_path = $pathinfo['dirname'] . '/' . $file_name . '.jpg';

// Convert to Jpeg
try {
$imagick_converted = new \Imagick($path);

if ($imagick_converted->getNumberImages() > 1) {
$imagick_converted->setIteratorIndex(0);
}

$imagick_converted->setImageFormat('jpeg');
$imagick_converted->setImageCompression(\Imagick::COMPRESSION_JPEG);
$imagick_converted->setImageCompressionQuality(92);

$imagick_converted->autoOrient();
$imagick_converted->writeImage($new_path);
} catch (\ImagickException $e) {
throw new CannotConvertMediaFileException('Failed to convert HEIC/HEIF to JPEG.', $e);
}

// Delete old file
$tmp_file->delete();

return new TemporaryJobFile($new_path);
}
}
23 changes: 23 additions & 0 deletions app/Actions/Photo/Convert/PhotoConverterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Actions\Photo\Convert;

use App\Contracts\PhotoCreate\PhotoConverter;
use App\Enum\ConvertableImageType;

class PhotoConverterFactory
{
public function make(string $extension): ?PhotoConverter
{
return match (true) {
ConvertableImageType::isHeifImageType($extension) => resolve(HeifToJpeg::class),
default => null,
};
}
}
1 change: 1 addition & 0 deletions app/Actions/Photo/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function add(NativeLocalFile $source_file, ?AbstractAlbum $album, ?int $f
);

$pre_pipes = [
Init\ConvertUnsupportedMedia::class,
Init\AssertSupportedMedia::class,
Init\FetchLastModifiedTime::class,
Init\MayLoadFileMetadata::class,
Expand Down
37 changes: 37 additions & 0 deletions app/Actions/Photo/Pipes/Init/ConvertUnsupportedMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Actions\Photo\Pipes\Init;

use App\Actions\Photo\Convert\PhotoConverterFactory;
use App\Contracts\PhotoCreate\InitPipe;
use App\DTO\PhotoCreate\InitDTO;
use App\Exceptions\CannotConvertMediaFileException;

class ConvertUnsupportedMedia implements InitPipe
{
/**
* Tries to convert the file to a supported format.
*
* @throws CannotConvertMediaFileException
*/
public function handle(InitDTO $state, \Closure $next): InitDTO
{
$ext = ltrim($state->source_file->getOriginalExtension(), '.');

$factory = new PhotoConverterFactory();
$converter = $factory->make($ext);
if ($converter === null) {
return $next($state);
}

$state->source_file = $converter->handle($state->source_file);

return $next($state);
}
}
17 changes: 17 additions & 0 deletions app/Contracts/PhotoCreate/PhotoConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Contracts\PhotoCreate;

use App\Image\Files\NativeLocalFile;
use App\Image\Files\TemporaryJobFile;

interface PhotoConverter
{
public function handle(NativeLocalFile $tmp_file): TemporaryJobFile;
}
25 changes: 25 additions & 0 deletions app/Enum/ConvertableImageType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Enum;

enum ConvertableImageType: string
{
case HEIC = 'heic';
case HEIF = 'heif';

public static function isHeifImageType(string $extension): bool
{
$extension = str($extension)->lower()->toString();

return in_array($extension, [
self::HEIC->value,
self::HEIF->value,
], true);
}
}
26 changes: 26 additions & 0 deletions app/Exceptions/CannotConvertMediaFileException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2026 LycheeOrg.
*/

namespace App\Exceptions;

use Symfony\Component\HttpFoundation\Response;

/**
* CannotConvertMediaFileException.
*
* Indicates that a media file cannot be converted to another format.
*/
class CannotConvertMediaFileException extends BaseLycheeException
{
public const string DEFAULT_MESSAGE = 'Cannot convert media file to another format';

public function __construct(string $msg = self::DEFAULT_MESSAGE, ?\Throwable $previous = null)
{
parent::__construct(Response::HTTP_UNPROCESSABLE_ENTITY, $msg, $previous);
}
}
7 changes: 7 additions & 0 deletions app/Services/Image/FileExtensionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FileExtensionService
IMAGETYPE_PNG,
IMAGETYPE_WEBP,
IMAGETYPE_AVIF,
20, // IMAGETYPE_HEIF;
];

public const SUPPORTED_IMAGE_FILE_EXTENSIONS = [
Expand All @@ -29,6 +30,8 @@ class FileExtensionService
'.gif',
'.webp',
'.avif',
'.heic',
'.heif',
];

public const SUPPORTED_VIDEO_FILE_EXTENSIONS = [
Expand All @@ -48,6 +51,8 @@ class FileExtensionService
'image/png',
'image/webp',
'image/avif',
'image/heif',
'image/heic',
];

public const SUPPORTED_VIDEO_MIME_TYPES = [
Expand All @@ -70,6 +75,8 @@ class FileExtensionService
'image/png' => '.png',
'image/webp' => '.webp',
'image/avif' => '.avif',
'image/heif' => '.heif',
'image/heic' => '.heic',
'video/mp4' => '.mp4',
'video/mpeg' => '.mpg',
'image/x-tga' => '.mpg',
Expand Down
Loading
Loading