concept st_asjpeg in category postgis

This is an excerpt from Manning's book PostGIS in Action, Third Edition.
PostGIS has a number of output functions for raster data such as
ST_AsPNG,ST_AsJPEG, andST_AsTiff.ST_AsGDALRasteris an all-purpose function that outputs to all formats supported by GDAL. A newer input companion function calledST_FromGDALRasterwill accept any raster supported by GDAL, provided that the entire raster fits into a single row of a table in a bytea data type column. With the combination of these two, you can easily perform powerful image processing using PostGIS. Take your old black and white photos, digitized them into JPEGs, copy them into a PostgreSQL table, storing the JPEG in a bytea column, apply colorization, and then dump them out back as JPEGs.
This would convert all your pictures (as long as they’re in a format supported by your PostGIS GDAL driver) to PostGIS
rasterformat and insert them into thebag_o_rasterstable. If you wanted to keep your images in a more common format, such as PNG or JPEG, then you’d convert back using one of the PostGIS raster companion output functions (ST_AsGDALRaster,ST_AsPNG, orST_AsJPEG) which we’ll cover in the next section.