Show a photograph

A how-to guide: convert a real photograph to teletext cells with sextants and place it on a page — full-screen, and as a thumbnail beside a post’s text.

import sextants

from sextile import OnOneFrame, Page, PageLayout, PageRequest, PageRouter, Sextile
from sextile.viewdata.tiles import Tile

router = PageRouter()

_photo = sextants.PRESETS["photo"]
_CELLS = sextants.convert_fragment(
    "docs/_static/blue-marble.jpg",
    40,
    20,
    fit=sextants.Fit.PAD,
    preprocess=_photo.preprocess,
    solve=_photo.solve,
).data


@router.page("1", name="photo", title="The Blue Marble")
async def photo(request: PageRequest) -> Page:
    return PageLayout(parts=[OnOneFrame(Tile.from_bytes(_CELLS, 40))]).build(request)


app = Sextile(name="Gallery", pages=[*router])
 THE BLUE MARBLE                      1a
  
                                        
               🬭🬹🬻 🬻🬺🬺🬹🬭                
             🬵    🬉🬱 🬱🬎🬎🬬🬱              
           🬞   🬞🬭🬭🬹🬅🬇🬎🬎 🬺🬺🬺🬏            
          🬦█🬝🬆🬮🬭🬭🬠██🬝🬄 🬸  🬬🬱            
         🬞  🬮 🬏🬁🬺 🬄 🬝🬡🬴🬡🬮🬁🬊             
         🬻█🬊🬊🬊🬊🬀🬀 🬺🬺🬯█🬆🬀🬞🬂🬊🬴🬙🬓          
        🬞  █ █    🬝🬝🬂█🬢    🬂🬺           
        ▐█🬶🬚🬍🬁██🬻🬝🬀🬦🬦🬑🬉🬀🬃   🬂🬟          
        ▐🬝🬬🬹🬋🬻█🬷█🬭 🬴  🬃 🬨🬏🬱🬁🬵█🬃         
        ▐▐🬭🬭  🬬██🬀  🬇🬇 🬊🬗 🬡█🬀         
        ▐█🬕🬠🬊█🬆🬡🬎█🬺██🬲 🬦🬦🬦▐🬏            
        🬁█▌🬠🬰  🬉🬬🬓🬨██🬝🬝🬻█▌🬏🬲 🬝          
         🬨█🬷🬻🬸🬺🬵    🬹🬷🬴🬷 🬟  🬨           
            ▌🬁  🬦🬏 🬞 🬖🬂🬂🬂 🬸🬀            
          🬁🬴  🬺🬏  🬖 🬁🬀🬭🬍🬂 🬉🬬            
           🬁🬬            🬕🬕             
             🬊🬬        🬝🬝🬂              
               🬂🬊🬎🬬█🬝🬎🬆🬀                
                                        
  
 0 index                                

sextants solves an image into teletext cells; convert_fragment(image, 40, 20, fit=Fit.PAD) fills the content area and Tile.from_bytes reads the bytes onto a Tile the page places. The photo preset (sextants.PRESETS["photo"]) suits continuous-tone photographs, which teletext has no in-between shades for — a bold, high-contrast subject like the Earth still reads. Sextile never imports sextants; it only places the cells.

For a post that shows a picture beside its text, place a small thumbnail as one part and the words as another:

import sextants

from sextile import Lines, OnOneFrame, Page, PageLayout, PageRequest, PageRouter, Sextile
from sextile.viewdata.tiles import Tile

router = PageRouter()

_photo = sextants.PRESETS["photo"]
_fragment = sextants.convert_fragment(
    "docs/_static/blue-marble.jpg",
    16,
    8,
    fit=sextants.Fit.CONTAIN,
    preprocess=_photo.preprocess,
    solve=_photo.solve,
)


@router.page("2", name="post", title="A post")
async def post(request: PageRequest) -> Page:
    thumbnail = Tile.from_bytes(_fragment.data, _fragment.width)
    words = Lines(["The Blue Marble: Earth seen", "from Apollo 17, photographed", "in December 1972."])
    return PageLayout(parts=[OnOneFrame(thumbnail), OnOneFrame(words)]).build(request)


app = Sextile(name="Forum", pages=[*router])
 A POST                               2a
  
    🬭🬹🬹🬭                                
  🬞🬜🬆🬰🬕🬂🬧🬏                              
  🬝🬬  🬆🬵🬱🬊                              
 ▐🬺🬰█🬆🬁🬀 🬊                              
 ▐▌🬚🬨🬺🬱🬞 🬸                              
  ██🬻█🬴🬘🬬▌                              
  🬁🬬   🬝🬝                               
    🬂🬊🬆🬂                                
The Blue Marble: Earth seen             
from Apollo 17, photographed            
in December 1972.                       
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
  
 0 index                                

Fit.CONTAIN sizes the thumbnail to the image’s own proportions within the box; the parts stack down the frame in order, the picture above the words. The full API is sextile.viewdata.tiles; converting bold poster art rather than a photograph is Show a picture, and a chart or an icon is Draw a chart and Draw an icon.


The photograph is *The Blue Marble (Earth from Apollo 17)* by the NASA/Apollo 17
crew — Harrison Schmitt or Ron Evans — December 1972, public domain, via
[Wikimedia Commons](https://commons.wikimedia.org/wiki/File:The_Earth_seen_from_Apollo_17.jpg).