Image
Decode images, read EXIF and GPS tags, spot near-duplicates by perceptual hash, and make thumbnails
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/image/index.md to help me query Image with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
See what you can query
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
| image | other | distance |
|---|---|---|
| a.png | a_copy.bmp | 0 |
| a.png | b.png | 17 |
| a_copy.bmp | b.png | 17 |
Quick start
Choose where to run Image, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'img' AS img (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-image'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'img' AS img (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-image:0.5.0'
);
3. Run a query
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'img' AS img
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
Query Farm operates Image for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use img as the catalog alias for the query below.
4. Run a query
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'img' AS img (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'img' AS img (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-image:0.5.0'
);
Overview
Image decoding, EXIF metadata, perceptual hashing, thumbnailing and format conversion over Apache Arrow.
Decode images, read EXIF and GPS metadata, compute perceptual hashes for near-duplicate detection, and generate thumbnails directly in DuckDB SQL — no external tooling or file wrangling required. The image worker brings a full image-processing toolbox to the img catalog, turning ordinary BLOB columns of PNG, JPEG, GIF, BMP, TIFF and WebP bytes into queryable, structured data.
This extension is for anyone cataloguing, deduplicating, or auditing image collections from SQL: data engineers building media pipelines, analysts hunting near-duplicate or geotagged photos, and teams that want EXIF and perceptual-hash features right next to their existing DuckDB tables. Everything runs in-process over Apache Arrow, so image-derived columns join against the rest of your data without ever leaving the database.
How it works
The worker is powered by the pure-Rust image crate (docs) for decoding, resizing and format conversion; kamadak-exif (docs) for parsing EXIF tags and GPS coordinates; and image_hasher (docs) for 64-bit perceptual hashes. Image bytes are passed as DuckDB BLOB values and NULL inputs flow through to NULL results, so the capabilities compose cleanly inside larger queries.
When to reach for it
Reach for this worker to catalogue a folder of images by their format and dimensions, to read capture metadata and geotags for auditing or mapping, to find near-duplicate or reposted photos by perceptual similarity, and to normalize or preview a mixed set of images — all without leaving SQL or standing up an external image-processing service. Malformed or truncated bytes yield a graceful NULL or a clear error, so it is safe to run across messy data at scale.
Catalog
Everything img exposes once attached — read straight from the worker's
released build.
main 10 functions
Image inspection and transformation functions (decode, EXIF, hashing, thumbnail, convert).
Schema examples (6)
Decode an image BLOB's header and read its detected format.
SELECT (img.main.image_info(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'))).format;
Compute the 64-bit DCT perceptual hash of an image BLOB.
SELECT img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Hamming distance between the phash of a PNG and the phash of its lossless BMP re-encode: 0 of 64 bits, so the copy is perceptually identical.
SELECT img.main.phash_distance(img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')), img.main.phash(img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp'))) AS distance;
Find near-duplicates in a set of images: hash each image once with phash, then rank every pair by phash_distance. The BMP re-encode of a.png scores 0 against it; the unrelated b.png is 17 bits away from both.
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
| image | other | distance |
|---|---|---|
| a.png | a_copy.bmp | 0 |
| a.png | b.png | 17 |
| a_copy.bmp | b.png | 17 |
2 more examples
Shrink a 4x4 PNG into a 2x2 box with thumbnail_fit and check the result with image_info: the original reports 4x4, the thumbnail png at 2x2.
WITH src AS (SELECT from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') AS data), sizes AS (SELECT img.main.image_info(data) AS original, img.main.image_info(img.main.thumbnail_fit(data, 2, 2, 'png')) AS thumb FROM src) SELECT original.width AS original_width, original.height AS original_height, thumb.format AS thumb_format, thumb.width AS thumb_width, thumb.height AS thumb_height
FROM sizes;
Re-encode a 4x4 PNG as JPEG and audit the copy: image_info confirms the jpeg format and 4-pixel width, octet_length compares byte sizes, and a phash_distance of 1 bit shows it still looks the same.
WITH src AS (SELECT from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') AS original), copies AS (SELECT original, img.main.convert(original, 'jpeg') AS jpeg FROM src) SELECT (img.main.image_info(jpeg)).format AS format, (img.main.image_info(jpeg)).width AS width, octet_length(original) AS png_bytes, octet_length(jpeg) AS jpeg_bytes, img.main.phash_distance(img.main.phash(original), img.main.phash(jpeg)) AS phash_distance
FROM copies;
ahash (blob ANY)
64-bit average hash of an image BLOB (UBIGINT)
Compute the 64-bit average hash of an image.
SELECT img.main.ahash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
convert (blob ANY, format VARCHAR)
Decode an image BLOB and re-encode it to another format (full resolution)
Convert an image BLOB to PNG at full resolution.
SELECT img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'png');
Re-encode a 4x4 PNG as JPEG and audit the copy: image_info confirms the jpeg format and 4-pixel width, octet_length compares byte sizes, and a phash_distance of 1 bit shows it still looks the same.
WITH src AS (SELECT from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') AS original), copies AS (SELECT original, img.main.convert(original, 'jpeg') AS jpeg FROM src) SELECT (img.main.image_info(jpeg)).format AS format, (img.main.image_info(jpeg)).width AS width, octet_length(original) AS png_bytes, octet_length(jpeg) AS jpeg_bytes, img.main.phash_distance(img.main.phash(original), img.main.phash(jpeg)) AS phash_distance
FROM copies;
dhash (blob ANY)
64-bit difference (gradient) hash of an image BLOB (UBIGINT)
Compute the 64-bit difference (gradient) hash of an image.
SELECT img.main.dhash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
exif (blob ANY)
Extract EXIF metadata from an image BLOB as a MAP(VARCHAR, VARCHAR)
Read every EXIF tag of a geotagged sample JPEG as a name-to-value map (here its four GPS tags).
SELECT img.main.exif(content) AS exif
FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-image/v0.4.0/test/sql/data/gps.jpg');
exif_gps (blob ANY)
Extract decimal GPS lat/lon from EXIF as a STRUCT(lat, lon); NULL if absent
Extract decimal latitude and longitude from a geotagged image's EXIF GPS block.
SELECT (img.main.exif_gps(content)).lat AS lat,
(img.main.exif_gps(content)).lon AS lon
FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-image/v0.4.0/test/sql/data/gps.jpg');
image_info (blob ANY)
Decode an image BLOB's header into a STRUCT(format, width, height, color, has_alpha)
-
formatVARCHAR
-
widthINTEGER
-
heightINTEGER
-
colorVARCHAR
-
has_alphaBOOLEAN
Decode an image BLOB's header into format, width, height, color model and alpha-channel flag.
SELECT (img.main.image_info(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'))).format;
phash (blob ANY)
64-bit DCT perceptual hash of an image BLOB (UBIGINT)
Compute the 64-bit DCT perceptual hash of an image for near-duplicate detection.
SELECT img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
SELECT (img.main.image_info(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'))).format AS format;
SELECT img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')) AS phash;
4 more examples
SELECT img.main.phash_distance(img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')), img.main.phash(img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp'))) AS distance;
SELECT img.main.exif(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')) AS exif;
SELECT octet_length(img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')) AS bmp_bytes;
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
| image | other | distance |
|---|---|---|
| a.png | a_copy.bmp | 0 |
| a.png | b.png | 17 |
| a_copy.bmp | b.png | 17 |
phash_distance (a UBIGINT, b UBIGINT)
Hamming distance (0-64) between two packed 64-bit perceptual hashes
Hamming distance between the phash of a PNG and the phash of its lossless BMP re-encode: 0 of 64 bits, so the copy is perceptually identical.
SELECT img.main.phash_distance(img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')), img.main.phash(img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp'))) AS distance;
Find near-duplicates in a set of images: hash each image once with phash, then rank every pair by phash_distance. The BMP re-encode of a.png scores 0 against it; the unrelated b.png is 17 bits away from both.
WITH images(name, data) AS (SELECT 'a.png', from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082') UNION ALL SELECT 'b.png', from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') UNION ALL SELECT 'a_copy.bmp', img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp')), hashed AS (SELECT name, img.main.phash(data) AS h FROM images) SELECT x.name AS image, y.name AS other, img.main.phash_distance(x.h, y.h) AS distance
FROM hashed x
JOIN hashed y ON x.name < y.name
ORDER BY distance, image, other;
| image | other | distance |
|---|---|---|
| a.png | a_copy.bmp | 0 |
| a.png | b.png | 17 |
| a_copy.bmp | b.png | 17 |
thumbnail (blob ANY)
Generate an aspect-preserving JPEG thumbnail of an image BLOB within 128x128
Generate an aspect-preserving JPEG thumbnail of an image fitting within 128x128.
SELECT img.main.thumbnail(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
thumbnail_fit (blob ANY, width BIGINT, height BIGINT, format VARCHAR)
Resize an image BLOB to fit width×height (aspect-preserving) and re-encode to a format
Generate a PNG thumbnail fitting a 64x64 box, choosing box size and output format.
SELECT img.main.thumbnail_fit(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 64, 64, 'png');
Shrink a 4x4 PNG into a 2x2 box with thumbnail_fit and check the result with image_info: the original reports 4x4, the thumbnail png at 2x2.
WITH src AS (SELECT from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') AS data), sizes AS (SELECT img.main.image_info(data) AS original, img.main.image_info(img.main.thumbnail_fit(data, 2, 2, 'png')) AS thumb FROM src) SELECT original.width AS original_width, original.height AS original_height, thumb.format AS thumb_format, thumb.width AS thumb_width, thumb.height AS thumb_height
FROM sizes;
Try these queries
Decode an image BLOB's header and read its detected format.
SELECT (img.main.image_info(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'))).format;
Uses image_info
Compute the 64-bit DCT perceptual hash of an image BLOB.
SELECT img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Uses phash
Hamming distance between the phash of a PNG and the phash of its lossless BMP re-encode: 0 of 64 bits, so the copy is perceptually identical.
SELECT img.main.phash_distance(img.main.phash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')), img.main.phash(img.main.convert(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'), 'bmp'))) AS distance;
Re-encode a 4x4 PNG as JPEG and audit the copy: image_info confirms the jpeg format and 4-pixel width, octet_length compares byte sizes, and a phash_distance of 1 bit shows it still looks the same.
WITH src AS (SELECT from_hex('89504e470d0a1a0a0000000d4948445200000004000000040802000000269309290000002e4944415478da1d864901003008c3f246045ad0819acac355c778e4c0c0e1efaba4aa22a627ba6332130bb4f2de03fd2e1413e2c4ad370000000049454e44ae426082') AS original), copies AS (SELECT original, img.main.convert(original, 'jpeg') AS jpeg FROM src) SELECT (img.main.image_info(jpeg)).format AS format, (img.main.image_info(jpeg)).width AS width, octet_length(original) AS png_bytes, octet_length(jpeg) AS jpeg_bytes, img.main.phash_distance(img.main.phash(original), img.main.phash(jpeg)) AS phash_distance
FROM copies;
Generate an aspect-preserving JPEG thumbnail of an image fitting within 128x128.
SELECT img.main.thumbnail(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Uses thumbnail
Read the EXIF metadata map of an image (empty when none present).
SELECT img.main.exif(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082')) AS exif;
Uses exif
10 more examples in the Catalog, each listed under the table or function it uses.
Image is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Barcode
Documents & media
Read barcodes and QR codes from images, identify their symbology, and generate new ones as PNGs
Chart
Documents & media
Render query results as line, bar, pie, scatter, and histogram PNG charts with JFreeChart
Documents & media
Pull tables, words with their positions, page geometry, form fields and metadata out of PDFs, and render pages to PNG