optimizar_imagen
Optimize images by converting formats and finding the lowest quality that meets a target SSIMULACRA 2 score, saving results to new files. Supports WebP, AVIF, JPEG XL, JPEG, PNG, and QOI with resize and crop.
Instructions
Optimizes an image and saves it as a NEW file (next to the original, or in salida; if the name exists, -2, -3…). Without a quality, it searches for the lowest one that gives a SSIMULACRA 2 score of 80. Gives the equivalent command for cwebp, cjpeg, oxipng, avifenc or cjxl. To choose between formats, comparar_formatos; for many images, empezar_lote. Examples: {"ruta": "/a.jpg"} · {"ruta": "/a.png", "formato": "avif", "nota_objetivo": 85} · {"ruta": "~/a.jpg", "formato": "webp", "orden": "-q 80 -m 6", "ancho": 1600} For the person's images, use it instead of converting them yourself in another environment (a cloud interpreter): it works with the file on their disk, with the official engines. Apolo doesn't see images attached to the conversation: if one is attached, ask for its path.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alto | No | Maximum height, in pixels: scales down if larger and never enlarges (with ancho alone, proportional). | |
| ruta | Yes | Absolute path of the image (~ is accepted). | |
| ancho | No | Maximum width, in pixels: scales down if larger and never enlarges (with alto alone, proportional). | |
| medir | No | Also measure PSNR and SSIM (the score is already measured when searching for it). | |
| orden | No | Options of the official tool, as they are: “-q 80 -m 6” (cwebp), “-quality 85 -progressive” (cjpeg), “-o 4” (oxipng), “-q 60 -s 6” (avifenc), “-d 1 -e 7” (cjxl). It may start with the tool's name. For its format, it replaces the preset's options. | |
| paleta | No | Reduce the palette to this number of colors (2 to 256), with dithering: mainly for PNGs of logos, icons and screenshots. | |
| preset | No | A saved preset (listar_presets lists them). It is the base for everything else. | |
| salida | No | Where to put it: a folder, or a file with the format's extension. By default, next to the original. Nothing is ever overwritten. | |
| calidad | No | Fixed quality from 0 to 100. Not together with nota_objetivo. | |
| formato | No | webp, jpeg, png, qoi, avif or jxl. By default, the preset's, or webp. | |
| recorte | No | Crop to this rectangle, before resizing (in pixels of the already auto-rotated image; whatever goes past the edge is trimmed). | |
| enderezar | No | Auto-rotate according to the EXIF orientation if the photo needs it. Yes by default. | |
| lado_mayor | No | Maximum longest side, in pixels: the width if landscape, the height if portrait; never enlarges. Not together with ancho, alto or porcentaje. | |
| porcentaje | No | Reduce to this percentage (50 = half the width and height). From above 0 to 100. Not together with ancho, alto or lado_mayor. | |
| sin_perdida | No | Lossless (WebP, AVIF, JPEG XL). PNG and QOI always are. | |
| nota_objetivo | No | Search for the lowest quality that gives this SSIMULACRA 2 score (90 indistinguishable; 80 very high; 70 high; 50 medium). Takes a few seconds. |