composer para agregar imagenes, descomentar el extension=gd del php.ini

This commit is contained in:
gianella
2026-06-12 11:01:28 -03:00
parent af45475010
commit 8ed7abc5fe
3 changed files with 50 additions and 108 deletions
+11 -9
View File
@@ -167,26 +167,28 @@ class ProductosController extends Controller
$file = $request->file('image'); $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 // 1. Iniciar el ImageManager (Sintaxis V2)
$manager = new \Intervention\Image\ImageManager(new \Intervention\Image\Drivers\Gd\Driver()); $manager = new \Intervention\Image\ImageManager(['driver' => 'gd']);
$image = $manager->decode($file->getRealPath()); $image = $manager->make($file->getRealPath());
// Redimensionar proporcionalmente si excede 1200px // 2. Redimensionar proporcionalmente si excede 1200px
if ($image->width() > 1200 || $image->height() > 1200) { 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 // 3. Comprimir a JPEG con 80% de calidad y convertir a texto para guardar
$encoded = $image->encode(new \Intervention\Image\Encoders\JpegEncoder(80)); $encoded = (string) $image->encode('jpg', 80);
// Nombre de archivo único // Nombre de archivo único
$path = 'products/' . uniqid() . '.jpg'; $path = 'products/' . uniqid() . '.jpg';
// Guardar en disco public // Guardar en disco public
Storage::disk('public')->put($path, $encoded->toString()); Storage::disk('public')->put($path, $encoded);
$validated['image_path'] = $path; $validated['image_path'] = $path;
} }
unset($validated['image']); unset($validated['image']);
+1 -1
View File
@@ -7,7 +7,7 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"intervention/image": "^4.1", "intervention/image": "^2.7",
"laravel-lang/common": "^6.7", "laravel-lang/common": "^6.7",
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/tinker": "^2.10.1" "laravel/tinker": "^2.10.1"
Generated
+37 -97
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "54a99d812eb7e5412ada7f4366c3065c", "content-hash": "5e9c902b68bea8cc7c5abfd1dfe26354",
"packages": [ "packages": [
{ {
"name": "archtechx/enums", "name": "archtechx/enums",
@@ -1569,32 +1569,50 @@
"time": "2025-02-03T10:55:03+00:00" "time": "2025-02-03T10:55:03+00:00"
}, },
{ {
"name": "intervention/gif", "name": "intervention/image",
"version": "5.0.1", "version": "2.7.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Intervention/gif.git", "url": "https://github.com/Intervention/image.git",
"reference": "bb395af960deffe64d70c976b4df9283f68e762d" "reference": "04be355f8d6734c826045d02a1079ad658322dad"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Intervention/gif/zipball/bb395af960deffe64d70c976b4df9283f68e762d", "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad",
"reference": "bb395af960deffe64d70c976b4df9283f68e762d", "reference": "04be355f8d6734c826045d02a1079ad658322dad",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^8.3" "ext-fileinfo": "*",
"guzzlehttp/psr7": "~1.1 || ^2.0",
"php": ">=5.4.0"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^2.1", "mockery/mockery": "~0.9.2",
"phpunit/phpunit": "^12.0", "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15"
"slevomat/coding-standard": "~8.0", },
"squizlabs/php_codesniffer": "^4" "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", "type": "library",
"extra": {
"laravel": {
"aliases": {
"Image": "Intervention\\Image\\Facades\\Image"
},
"providers": [
"Intervention\\Image\\ImageServiceProvider"
]
},
"branch-alias": {
"dev-master": "2.4-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Intervention\\Gif\\": "src" "Intervention\\Image\\": "src/Intervention/Image"
} }
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@@ -1608,93 +1626,19 @@
"homepage": "https://intervention.io/" "homepage": "https://intervention.io/"
} }
], ],
"description": "PHP GIF Encoder/Decoder", "description": "Image handling and manipulation library with support for Laravel integration",
"homepage": "https://github.com/intervention/gif", "homepage": "http://image.intervention.io/",
"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",
"keywords": [ "keywords": [
"gd", "gd",
"image", "image",
"imagick", "imagick",
"resize", "laravel",
"thumbnail", "thumbnail",
"watermark" "watermark"
], ],
"support": { "support": {
"issues": "https://github.com/Intervention/image/issues", "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": [ "funding": [
{ {
@@ -1704,13 +1648,9 @@
{ {
"url": "https://github.com/Intervention", "url": "https://github.com/Intervention",
"type": "github" "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", "name": "laravel-lang/actions",
@@ -10091,5 +10031,5 @@
"php": "^8.2" "php": "^8.2"
}, },
"platform-dev": {}, "platform-dev": {},
"plugin-api-version": "2.6.0" "plugin-api-version": "2.9.0"
} }