[Tex/LaTex] ConTeXt: Expand background image to fill page

backgroundscontextgraphicstitles

Background

Looking to make a background image scale to fill an entire page.

Code

I tried changing the dimensions of the page to fill the entire area and then drop in an external image:

\setuplayout[
  backspace=0mm,
  leftmargin=0mm,
  rightmargin=0mm,
  topdistance=0mm,
  header=0mm,
  footer=0mm,
]

\starttext

\startfrontmatter

  % Title page (front cover).
  \startstandardmakeup
    % Front Cover Photo
    % Front Cover Photo citation (author, author url, license, license url)
    \externalfigure[cover.png][width=\paperwidth,height=\paperheight]
  \stopstandardmakeup

  % Copyright page.
  \startstandardmakeup
    % date
    % author

    Copyright
  \stopstandardmakeup

  % Table of Contents.
  \completecontent
\stopfrontmatter

\stoptext

Update

Other attempts that don't quite work.

Layer

Using a defined layer:

\definelayer[cover][
  x=0mm,
  y=0mm,
  width=\paperwidth,
  height=\paperheight,
]

\setlayer[cover][
  hoffset=0mm,
  voffset=0mm,
]{%
  \framed[
    frame=off
    width=\paperwidth,
    height=\paperheight,
  ]{%
    \externalfigure[cover.png][width=\paperwidth,height=\paperheight]
  }
}

\starttext

\startfrontmatter
  \setupbackgrounds[page][background=cover]
  \startstandardmakeup
  \stopstandardmakeup
  \setupbackground[page][background=]
\stopfrontmatter
\stoptext

This produces a white border along the left and bottom edges:

White Border

Problem

There is a small amount of whitespace that is not taken up by the image:

Extra Whitespace

Related

The wiki shows how to fill a page using an MP graphic, but that seems to be overly complicated for just adding an image to the page:

The question on filling the background graphic across two pages is similar, but has text on top of the image:

Additional Information

External figures are set up as follows:

\setupexternalfigures[
  order={svg,pdf,png,jpg},
  location=global,
  width=\hsize,
]

Question

What is the proper way to scale an image, without respecting its aspect ratio, such that it fills the entire page?

Best Answer

Normally, you use \setupbackgrounds[page][background=...] to set a page background. So, one option is to use

\setupbackgrounds[page][background=...]
\startstandardmakeup
...
\stopstandardmakeup
\setupbackground[page][background=] %Reset

A more elegant option is to extend the makeup mechanism to accept the background key:

\unprotect
\appendtoks
  \setupbackgrounds[\v!page][\c!background=\makeupparameter\c!background]
\to \t_page_makeup_every_setup
\protect

Then you can use

\setupexternalfigures[location={local,default,global}]

\defineoverlay
  [backgroundimage]
  [{\externalfigure[cow.pdf][width=\overlaywidth, height=\overlayheight]}]


\starttext

\startstandardmakeup[background=backgroundimage]
  Whatever
\stopstandardmakeup

Next

\stoptext

If you just want to include an image, you can also use:

\startTEXpage
  \externalfigure[cow.pdf][width=\paperwidth, height=\paperheight]
\stopTEXpage
Related Question