/snap_to_device{ 6 dict begin matrix currentmatrix dup 0 get 0 eq 1 index 3 get 0 eq and 1 index 1 get 0 eq 2 index 2 get 0 eq and or exch pop{ 1 1 dtransform 0 gt exch 0 gt/AGMIMG_xSign? exch def/AGMIMG_ySign? exch def 0 0 transform AGMIMG_ySign?{floor 0.1 sub}{ceiling 0.1 add}ifelse exch AGMIMG_xSign?{floor 0.1 sub}{ceiling 0.1 add}ifelse exch itransform/AGMIMG_llY exch def/AGMIMG_llX exch def 1 1 transform AGMIMG_ySign?{ceiling 0.1 add}{floor 0.1 sub}ifelse exch AGMIMG_xSign?{ceiling 0.1 add}{floor 0.1 sub}ifelse exch itransform/AGMIMG_urY exch def/AGMIMG_urX exch def [AGMIMG_urX AGMIMG_llX sub 0 0 AGMIMG_urY AGMIMG_llY sub AGMIMG_llX AGMIMG_llY]concat }{ }ifelse end}def Snaps To device pixels to work: for align with device pixel. Snap the image geometry to the device pixels, producing a rectangle which is snapped. 6 item dictionary begin /matrix currentmatrix %array dup 0 %duplicate zero posiotn ie element array get 0 the index item from the top stack element array ie 1.333 0 eq % is these are equal , push the result in the stack (false say)