Skip to content

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
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;
Result
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.

setup.sql
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;

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'
);

3. Run a query

query.sql
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;
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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]'
);

Overview

Image decoding, EXIF metadata, perceptual hashing, thumbnailing and format conversion over Apache Arrow.

Catalog

Everything img exposes once attached — read straight from the worker's released build.

img 1 schema
main 10 functions

Image inspection and transformation functions (decode, EXIF, hashing, thumbnail, convert).

Schema examples (6)
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;
Result
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;
Scalar functions
ahash (blob ANY) 1 example

64-bit average hash of an image BLOB (UBIGINT)

Arguments
blob ANY
Image bytes (BLOB)
ReturnsUBIGINT
Example

Compute the 64-bit average hash of an image.

SELECT img.main.ahash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Link
convert (blob ANY, format VARCHAR) 2 examples

Decode an image BLOB and re-encode it to another format (full resolution)

Arguments
blob ANY
Image bytes (BLOB)
format VARCHAR
Target format: jpeg, png, webp, gif, bmp, tiff
ReturnsBLOB
Examples (2)

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;
Link
dhash (blob ANY) 1 example

64-bit difference (gradient) hash of an image BLOB (UBIGINT)

Arguments
blob ANY
Image bytes (BLOB)
ReturnsUBIGINT
Example

Compute the 64-bit difference (gradient) hash of an image.

SELECT img.main.dhash(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Link
exif (blob ANY) 1 example

Extract EXIF metadata from an image BLOB as a MAP(VARCHAR, VARCHAR)

Arguments
blob ANY
Image bytes (BLOB)
ReturnsMAP(VARCHAR, VARCHAR)
Example

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');
Link
exif_gps (blob ANY) 1 example

Extract decimal GPS lat/lon from EXIF as a STRUCT(lat, lon); NULL if absent

Arguments
blob ANY
Image bytes (BLOB)
ReturnsSTRUCT(lat DOUBLE, lon DOUBLE)
Example

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');
Link
image_info (blob ANY) 1 example

Decode an image BLOB's header into a STRUCT(format, width, height, color, has_alpha)

Arguments
blob ANY
Image bytes (BLOB)
ReturnsSTRUCT of 5 fields
STRUCT 5 fields
  • formatVARCHAR
  • widthINTEGER
  • heightINTEGER
  • colorVARCHAR
  • has_alphaBOOLEAN
Example

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;
Link
phash (blob ANY) 7 examples

64-bit DCT perceptual hash of an image BLOB (UBIGINT)

Arguments
blob ANY
Image bytes (BLOB)
ReturnsUBIGINT
Examples (7)

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;
Result
image other distance
a.png a_copy.bmp 0
a.png b.png 17
a_copy.bmp b.png 17
Link
phash_distance (a UBIGINT, b UBIGINT) 2 examples

Hamming distance (0-64) between two packed 64-bit perceptual hashes

Arguments
a UBIGINT
The first perceptual hash to compare, as produced by phash/dhash/ahash
b UBIGINT
The second perceptual hash to compare against the first
ReturnsINTEGER
Examples (2)

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;
Result
image other distance
a.png a_copy.bmp 0
a.png b.png 17
a_copy.bmp b.png 17
Link
thumbnail (blob ANY) 1 example

Generate an aspect-preserving JPEG thumbnail of an image BLOB within 128x128

Arguments
blob ANY
Image bytes (BLOB)
ReturnsBLOB
Example

Generate an aspect-preserving JPEG thumbnail of an image fitting within 128x128.

SELECT img.main.thumbnail(from_hex('89504e470d0a1a0a0000000d4948445200000002000000020802000000fdd49a73000000164944415478da6360608812608862601088121088020009be01a9f633974e0000000049454e44ae426082'));
Link
thumbnail_fit (blob ANY, width BIGINT, height BIGINT, format VARCHAR) 2 examples

Resize an image BLOB to fit width×height (aspect-preserving) and re-encode to a format

Arguments
blob ANY
Image bytes (BLOB)
width BIGINT
Maximum thumbnail width in pixels (must be positive)
height BIGINT
Maximum thumbnail height in pixels (must be positive)
format VARCHAR
Output format: jpeg, png, webp, gif, bmp, tiff
ReturnsBLOB
Examples (2)

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;
Link

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;

Uses phash_distancephashconvert

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;

Uses convertimage_infophash_distancephash

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.