Documentation Index
Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
Use this file to discover all available pages before exploring further.
Problem
You need to resize, rotate, crop, or convert hundreds of images—and keep track of all the transformed versions.Solution
What’s in this recipe:- Basic image operations (resize, rotate, flip, crop)
- Track image properties
- Iterate on transformations before adding to your table
.select() with .collect() to preview results on sample
images—nothing is stored in your table. If you want to collect only the
first few rows, use .head(n) instead of .collect(). Once you’re
satisfied, use .add_computed_column() to apply the transformation to
all images in your table.
For more on this workflow, see Get fast feedback on
transformations.
Setup
Load images
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘image_demo’.
<pixeltable.catalog.dir.Dir at 0x13984d780>
Created table ‘images’.
Inserting rows into `images`: 0 rows [00:00, ? rows/s]
Inserting rows into `images`: 3 rows [00:00, 708.38 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.
Iterate: check image properties for a few images first
Use.select() to define the transformation, then .collect() to
execute and return results. If you want to collect only the first few
rows, use .head(n) instead of .collect(). Nothing is stored in your
table.
Pixeltable includes these built-in functions for image properties:
.height- Get image height in pixels.width- Get image width in pixels.mode- Get color mode (RGB, RGBA, L for grayscale, etc.)
Add: check image properties for all images in your table
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
3 rows updated, 6 values computed.
Iterate: resize a few images first
Use.select() to define the transformation, then .collect() to
execute and return results. If you want to collect only the first few
rows, use .head(n) instead of .collect(). Nothing is stored in your
table.
Pixeltable includes a built-in function for resizing image files with
PIL:
.resize(width, height)- Change image dimensions
Add: resize all images in your table
Once you’re satisfied with the results, use.add_computed_column()
with the same expression. This processes all rows and stores the results
permanently in your table.
Added 3 column values with 0 errors.
3 rows updated, 3 values computed.
Iterate: rotate a few images first
Use.select() to define the transformation, then .collect() to
execute and return results. If you want to collect only the first few
rows, use .head(n) instead of .collect(). Nothing is stored in your
table.
Pixeltable includes a built-in function for rotating image files with
PIL:
.rotate(degrees)- Rotate image by specified degrees
Add: rotate all images in your table
Once you’re satisfied with the results, use.add_computed_column()
with the same expression. This processes all rows and stores the results
permanently in your table.
Added 3 column values with 0 errors.
3 rows updated, 3 values computed.
Iterate: flip a few images first
Use.select() to define the transformation, then .collect() to
execute and return results. If you want to collect only the first few
rows, use .head(n) instead of .collect(). Nothing is stored in your
table.
Pixeltable includes a built-in function for transposing image files with
PIL (note that for this transform you will need import PIL to access the
FLIP_* constants):
.transpose(Image.FLIP_TOP_BOTTOM)- Flip image vertically.transpose(Image.FLIP_LEFT_RIGHT)- Mirror image horizontally
Add: flip all images in your table
Once you’re satisfied with the results, use.add_computed_column()
with the same expression. This processes all rows and stores the results
permanently in your table.
Added 3 column values with 0 errors.
Added 3 column values with 0 errors.
3 rows updated, 3 values computed.
Iterate: crop a few images first
Use.select() to define the transformation, then .collect() to
execute and return results. If you want to collect only the first few
rows, use .head(n) instead of .collect(). Nothing is stored in your
table.
Pixeltable includes a built-in function for cropping image files with
PIL:
.crop(box)- Extract a rectangular region from the image (box format:(left, top, right, bottom))
Add: crop all images in your table
Once you’re satisfied with the results, use.add_computed_column()
with the same expression. This processes all rows and stores the results
permanently in your table.
Added 3 column values with 0 errors.
3 rows updated, 3 values computed.
Explanation
How PIL transformations work in Pixeltable: Pixeltable provides built-in functions that wrap PIL (Pillow) operations for image manipulation. These functions work directly on image columns in your table—no need to write loops or manage file I/O. When you call.resize(), .rotate(), or other methods on an image column,
Pixeltable handles applying the transformation to each image
automatically.
All these transformations use standard PIL operations under the hood.
For more details on PIL functionality, see the Pillow
documentation.
To customize transformations:
- Resize: Change dimensions with
.resize((width, height))- specify target size in pixels - Rotate: Rotate counterclockwise with
.rotate(degrees)- use negative values for clockwise rotation - Flip: Use
.transpose(Image.FLIP_LEFT_RIGHT)for horizontal mirror or.transpose(Image.FLIP_TOP_BOTTOM)for vertical flip - Crop: Extract regions with
.crop((left, top, right, bottom))- coordinates are in pixels from top-left origin - Properties: Access
.width,.height, and.modeto get image dimensions and color mode
.select() just picks which columns to view.
In Pixeltable, .select() also lets you compute new transformations on
the fly—define new columns without storing them. This makes .select()
perfect for testing transformations before you commit them.
When you use .select(), you’re creating a query that doesn’t execute
until you call .collect(). You must use .collect() to execute the
query and return results—nothing is stored in your table. If you want to
collect only the first few rows, use .head(n) instead of .collect()
to test on a subset before processing your full dataset. Once satisfied,
use .add_computed_column() with the same expression to persist results
permanently.
For more on this workflow, see Get fast feedback on
transformations.