removed from project

This commit is contained in:
2024-04-24 18:06:38 +10:00
parent 18e0a2afd2
commit 2b924fac4b
4 changed files with 0 additions and 263 deletions

View File

@@ -1,97 +0,0 @@
<?php
namespace App\MediaServices\Converters;
use App\Exceptions\MediaServiceException;
use App\Http\Controllers\MediaController;
use App\MediaServices\MediaService;
use App\MediaServices\MediaServiceData;
use App\Models\Media;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Facades\Image;
use Intervention\Image\ImageManager;
use Intervention\Image\Interfaces\ImageInterface;
class HEICToJPEG implements MediaService
{
/**
* Return if the supplied mime type is supported by this processor.
*
* @param string $mimeType The mime type to test.
* @return boolean If the mime type is supported.
*/
public function mimeSupported(string $mimeType): bool
{
return $mimeType === 'image/heic' || $mimeType === 'image/heif';
}
/**
* Return if the supplied service key is supported by this processor.
*
* @param string $key The service key to test.
* @return boolean If the service key is supported.
*/
public function serviceSupports(string $key): bool {
return in_array($key, [
ImageInterface::class
]);
}
/**
* Process the media item.
*
* @throws MediaServiceException If the processing fails.
*
* @param Media $media The media model.
* @param MediaServiceData $data The data for the media service.
*
* @return void
*/
public function process(Media $media, MediaServiceData $data): void
{
$image = $data->getData(ImageInterface::class, function() use ($data) {
$manager = new ImageManager(new Driver());
$image = $manager->read($data->file());
if($image === null) {
throw new MediaServiceException('Could not read file.');
}
return $image;
});
$quality = $data->option('heictojpeg', 'quality', 90);
$encoded = $image->toJpeg($quality);
$encoded->save($data->file()); // this needs to be renamed with the new extension
if(!$data->nextSupports(ImageInterface::class)) {
$image->save();
$data->removeData(ImageInterface::class);
}
Image::make($tempFile)
->save($tempJpgFile);
$media->set
$media->mime_type = 'image/jpeg';
/*****/
$filePath = $file['dirname'] . '/' . $file['name'] . '.' . $file['extension'];
$jpgFileName = MediaController::makeNewFilename($file['name'], 'jpg');
Image::make($filePath)
->save($file['dirname'] . '/' . $jpgFileName);
$file['name'] = pathinfo($jpgFileName, PATHINFO_FILENAME);
$file['extension'] = 'jpg';
$file['mime_type'] = 'image/jpeg';
$file['size'] = filesize($file['dirname'] . '/' . $jpgFileName);
unlink($filePath);
return true;
}
}

View File

@@ -1,37 +0,0 @@
<?php
namespace App\MediaServices;
use App\Exceptions\MediaServiceException;
use App\Models\Media;
interface MediaService
{
/**
* Return if the supplied mime type is supported by this processor.
*
* @param string $mimeType The mime type to test.
* @return boolean If the mime type is supported.
*/
public function mimeSupported(string $mimeType): bool;
/**
* Return if the supplied service key is supported by this processor.
*
* @param string $key The service key to test.
* @return boolean If the service key is supported.
*/
public function serviceSupports(string $key): bool;
/**
* Process the media item.
*
* @throws MediaServiceException If the processing fails.
*
* @param Media $media The media model.
* @param MediaServiceData $data The data for the media service.
*
* @return void
*/
public function process(Media $media, MediaServiceData $data): void;
}

View File

@@ -1,53 +0,0 @@
<?php
namespace App\MediaServices;
class MediaServiceData
{
/**
* The data array.
*
* @var array
*/
protected $data = [];
/**
* Get the data from the data array.
*
* @param string $key The key to get.
* @param mixed $default The default value to return if the key does not exist.
* @return mixed The value of the key.
*/
public function get(string $key, $default = null)
{
return $this->data[$key] ?? $default;
}
/**
* Set the data in the data array.
*
* @param string $key The key to set.
* @param mixed $value The value to set.
* @return void
*/
public function set(string $key, $value): void
{
$this->data[$key] = $value;
}
/**
* Get the data from the data array or create it if it does not exist.
*
* @param string $key The key to get.
* @param callable $default The default value to return if the key does not exist.
* @return mixed The value of the key.
*/
public function getChainData(string $key, callable $default)
{
if (!isset($this->data[$key])) {
$this->data[$key] = $default();
}
return $this->data[$key];
}
}

View File

@@ -1,76 +0,0 @@
<?php
namespace App\MediaServices\Transformers;
use App\Exceptions\MediaServiceException;
use App\MediaServices\MediaService;
use App\MediaServices\MediaServiceData;
use App\Models\Media;
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Interfaces\ImageInterface;
class ImageRotate implements MediaService
{
/**
* Return if the supplied mime type is supported by this processor.
*
* @param string $mimeType The mime type to test.
* @return boolean If the mime type is supported.
*/
public function mimeSupported(string $mimeType): bool {
return in_array($mimeType, [
'image/jpeg',
'image/webp',
'image/gif',
'image/png',
'image/avif',
'image/heic',
'image/bmp'
]);
}
/**
* Return if the supplied service key is supported by this processor.
*
* @param string $key The service key to test.
* @return boolean If the service key is supported.
*/
public function serviceSupports(string $key): bool {
return in_array($key, [
'rotate',
ImageInterface::class
]);
}
/**
* Process the media item.
*
* @throws MediaServiceException If the processing fails.
*
* @param Media $media The media model.
* @param MediaServiceData $data The data for the media service.
*
* @return void
*/
public function process(Media $media, MediaServiceData $data): void
{
$image = $data->getData(ImageInterface::class, function() use ($data) {
$manager = new ImageManager(new Driver());
$image = $manager->read($data->file());
if($image === null) {
throw new MediaServiceException('Could not read file.');
}
return $image;
});
$degrees = $data->option('rotate', 'degrees', 90);
$image->rotate($degrees);
if(!$data->nextSupports(ImageInterface::class)) {
$image->save();
$data->removeData(ImageInterface::class);
}
}
}