diff --git a/app/Http/Controllers/ProductosController.php b/app/Http/Controllers/ProductosController.php index a3df1ac..916bf75 100644 --- a/app/Http/Controllers/ProductosController.php +++ b/app/Http/Controllers/ProductosController.php @@ -167,26 +167,28 @@ class ProductosController extends Controller $file = $request->file('image'); - // Elevar temporalmente el límite de memoria para procesar la imagen - ini_set('memory_limit', '512M'); + ini_set('memory_limit', '512M'); - // Usar Intervention Image v4 con driver GD para procesar la imagen - $manager = new \Intervention\Image\ImageManager(new \Intervention\Image\Drivers\Gd\Driver()); - $image = $manager->decode($file->getRealPath()); + // 1. Iniciar el ImageManager (Sintaxis V2) + $manager = new \Intervention\Image\ImageManager(['driver' => 'gd']); + $image = $manager->make($file->getRealPath()); - // Redimensionar proporcionalmente si excede 1200px + // 2. Redimensionar proporcionalmente si excede 1200px if ($image->width() > 1200 || $image->height() > 1200) { - $image->scale(width: 1200, height: 1200); + $image->resize(1200, 1200, function ($constraint) { + $constraint->aspectRatio(); // Mantiene la proporción original (no deforma) + $constraint->upsize(); // Evita que imágenes chicas se agranden y pixelen + }); } - // Comprimir a JPEG con 80% de calidad - $encoded = $image->encode(new \Intervention\Image\Encoders\JpegEncoder(80)); + // 3. Comprimir a JPEG con 80% de calidad y convertir a texto para guardar + $encoded = (string) $image->encode('jpg', 80); // Nombre de archivo único $path = 'products/' . uniqid() . '.jpg'; // Guardar en disco public - Storage::disk('public')->put($path, $encoded->toString()); + Storage::disk('public')->put($path, $encoded); $validated['image_path'] = $path; } unset($validated['image']); diff --git a/composer.json b/composer.json index 60fd95c..85ab590 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "MIT", "require": { "php": "^8.2", - "intervention/image": "^4.1", + "intervention/image": "^2.7", "laravel-lang/common": "^6.7", "laravel/framework": "^12.0", "laravel/tinker": "^2.10.1" diff --git a/composer.lock b/composer.lock index 2764864..8df5dcc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "54a99d812eb7e5412ada7f4366c3065c", + "content-hash": "5e9c902b68bea8cc7c5abfd1dfe26354", "packages": [ { "name": "archtechx/enums", @@ -1569,32 +1569,50 @@ "time": "2025-02-03T10:55:03+00:00" }, { - "name": "intervention/gif", - "version": "5.0.1", + "name": "intervention/image", + "version": "2.7.2", "source": { "type": "git", - "url": "https://github.com/Intervention/gif.git", - "reference": "bb395af960deffe64d70c976b4df9283f68e762d" + "url": "https://github.com/Intervention/image.git", + "reference": "04be355f8d6734c826045d02a1079ad658322dad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Intervention/gif/zipball/bb395af960deffe64d70c976b4df9283f68e762d", - "reference": "bb395af960deffe64d70c976b4df9283f68e762d", + "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad", + "reference": "04be355f8d6734c826045d02a1079ad658322dad", "shasum": "" }, "require": { - "php": "^8.3" + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1 || ^2.0", + "php": ">=5.4.0" }, "require-dev": { - "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^12.0", - "slevomat/coding-standard": "~8.0", - "squizlabs/php_codesniffer": "^4" + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" }, "type": "library", + "extra": { + "laravel": { + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + }, + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ] + }, + "branch-alias": { + "dev-master": "2.4-dev" + } + }, "autoload": { "psr-4": { - "Intervention\\Gif\\": "src" + "Intervention\\Image\\": "src/Intervention/Image" } }, "notification-url": "https://packagist.org/downloads/", @@ -1608,93 +1626,19 @@ "homepage": "https://intervention.io/" } ], - "description": "PHP GIF Encoder/Decoder", - "homepage": "https://github.com/intervention/gif", - "keywords": [ - "animation", - "gd", - "gif", - "image" - ], - "support": { - "issues": "https://github.com/Intervention/gif/issues", - "source": "https://github.com/Intervention/gif/tree/5.0.1" - }, - "funding": [ - { - "url": "https://paypal.me/interventionio", - "type": "custom" - }, - { - "url": "https://github.com/Intervention", - "type": "github" - }, - { - "url": "https://ko-fi.com/interventionphp", - "type": "ko_fi" - } - ], - "time": "2026-05-03T06:04:47+00:00" - }, - { - "name": "intervention/image", - "version": "4.1.2", - "source": { - "type": "git", - "url": "https://github.com/Intervention/image.git", - "reference": "ba4a7cc8042882d479a78b0835f3f0e991e40a71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Intervention/image/zipball/ba4a7cc8042882d479a78b0835f3f0e991e40a71", - "reference": "ba4a7cc8042882d479a78b0835f3f0e991e40a71", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "intervention/gif": "^5", - "php": "^8.3" - }, - "require-dev": { - "mockery/mockery": "^1.6", - "phpstan/phpstan": "^2.1", - "phpunit/phpunit": "^12.0", - "slevomat/coding-standard": "~8.0", - "squizlabs/php_codesniffer": "^4" - }, - "suggest": { - "ext-exif": "Recommended to be able to read EXIF data properly." - }, - "type": "library", - "autoload": { - "psr-4": { - "Intervention\\Image\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Oliver Vogel", - "email": "oliver@intervention.io", - "homepage": "https://intervention.io" - } - ], - "description": "PHP Image Processing", - "homepage": "https://image.intervention.io", + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", "keywords": [ "gd", "image", "imagick", - "resize", + "laravel", "thumbnail", "watermark" ], "support": { "issues": "https://github.com/Intervention/image/issues", - "source": "https://github.com/Intervention/image/tree/4.1.2" + "source": "https://github.com/Intervention/image/tree/2.7.2" }, "funding": [ { @@ -1704,13 +1648,9 @@ { "url": "https://github.com/Intervention", "type": "github" - }, - { - "url": "https://ko-fi.com/interventionphp", - "type": "ko_fi" } ], - "time": "2026-05-23T06:51:28+00:00" + "time": "2022-05-21T17:30:32+00:00" }, { "name": "laravel-lang/actions", @@ -10091,5 +10031,5 @@ "php": "^8.2" }, "platform-dev": {}, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" }