Cropping PDF Documents

    Sometimes it’s useful to be able to crop all pages in a PDF document. ImageMagick1 can do this, but the command you’ll need is a little nuanced:

    convert \
        -density 300 \
        -crop 2550x3616+0+0 \
        +repage \
        input.pdf \
        -density 300 \
        -compress jpeg \
        -quality 75 \
        output.pdf
    

    Input File

    • -density 300

      Specify the input density (given in dots per inch) of your PDF document. Without this, ImageMagick will default to 72 DPI, leading to a significant reduction in resolution. PDF documents created with a document scanner are typically 150 DPI or 300 DPI.

    • -crop 2550x3616+0+0

      Select the crop, given as a geometry. For most common use-cases, the widthxheight+offsetX+offsetY format will suffice.

    • +repage

      Ensure the page size of the output PDF document matches your crop. Without this, the page size of the output PDF document will be that of the input PDF document, leading to white borders.

    • input.pdf

      The path of the input document.

    Output File

    • -density 300

      Ensure the output density matches the input density. Without this, your output PDF document will have different physical dimensions to your input PDF document.

    • -compress jpeg

      Compress the images in the output PDF document as JPEG. Omitting this results in huge files.

    • -quality 75

      Specify the JPEG output quality (on a scale of 0-100). I find 75 represents a good compromise between file size and quality.

    • output.pdf

      The path of the output document.


    1. ImageMagick is available through Homebrew on macOS, and can be installed with the command brew install imagemagick

    Adidas Posters

    Every time I visit Phil–a hipster bookstore and coffee shop in Vienna–I’m struck by the wonderful hand drawn Adidas adverts they have along one of the walls.

    While perhaps not the most politically correct, these are a fantastic example of late 70s/early 80s fashion and design.

    Bread

    When I have time, I like to bake my own bread. It’s a very simple recipe Junko kindly gave me, and I thought it might be nice to share here.

    Freshly baked loaf

    Ingredients

    • Wholemeal or Brown Flour - 500g
    • Butter - 25g
    • Dried Yeast - 7g (1 packet)
    • Salt - 1 tea spoon (4 turns of a salt mill)
    • Warm Water - 330ml
    • Dried Fruit or Nuts - Handful (optional)

    Method

    1. Combine the flour, yeast, and salt in a large bowl.
    2. Cut the butter into small pieces and add it to the bowl.
    3. Crumble the butter and flour by rubbing the mixture between your fingertips until no lumps of butter remain.
    4. Make a small well in the centre of the mixture, and add the warm water. Stir gently with a spoon, folding the flour and water together.
    5. Once it becomes difficult to stir, knead by hand for 5 to 10 minutes. The dough should leave the bowl clean, and shouldn’t stick to your hand: if the mixture seems to be too dry to clean the bowl, add a drop more water; too sticky, add a pinch more flour.
    6. Place a damp cloth (I use a tea towel) over the top of the bowl, and leave the dough to rest in a warm place for between 30 minutes and an hour. It should roughly double in size during this time. If your kitchen is short on warm places, you can always rest the bowl inside a larger bowl or pan of warm water.
    7. Once it has risen, put a little flour on hands and knead the dough back down a little. Add some dried fruit or nuts (raisins, cranberries, walnuts, etc) at this point if you would like.
    8. Gently press the dough into an un-greased loaf tin, levelling the top.
    9. Bake in a fan oven at 230ºC (450ºF) for 15 minutes.
    10. Reduce the temperature to 200ºC (400ºF), and bake for a further 15 minutes.
    11. Remove the bread from the loaf tin, and leave to stand on a cooling rack.

    Sliced loaf

    Anytime Clock

    A little over a year ago, I created the Anytime platform as a way of keeping track of the time of day for various friends, family, and colleagues. It’s especially useful now Junko and I are living on different sides of the Atlantic.

    The Anytime iOS app and widget are great when on-the-go, but they don’t provide the same immediacy as a physical clock. So, after some encouragement by a colleague, I started work on a Nixie tube Anytime clock.

    First digit working

    Pictures do not do Nixie tubes justice; they have a beautiful blue glow when seen in the flesh.

    Being one of my more complex electronics projects in a while, I decided to start simple, using the ‘Smart Nixie tube’ kit from Switchmode Design. I’m glad I did—even remembering how to read resistors presented a challenge:

    Learning how to read resistors

    Much to my surprise, everything worked first time—more a comment on fantastic instructions than on my soldering skills.

    Completed circuit board

    The board can be controlled over serial, and supports chaining of up to six digits. I plan to purchase a further three kits to produce a four digit clock. Control will ultimately be performed by a Raspberry Pi (most likely a Zero), for which I’ve already produced a small Python Anytime client:

    Raspberry Pi control board

    Railway Journeys

    Ever since travelling on the Trans-Siberian Railway some 10 years ago, I’ve wondered how one might capture such a journey: photos do not do the ever-changing view justice, and video remains difficult to consume. Even time-lapse videos do not allow the journey to be viewed as a whole, meaning macro changes are lost.

    On a recent trip from London Euston to Chester, I tried something new. Using the very simple technique of joining fixed-width strips from each frame of a video, I was able to produce the following:

    London Euston to Chester

    This represents about 2 minutes of video with each frame contributing 2 pixels to the overall image. Increasing the width of each frame to 5 pixels, objects on the horizon have roughly the correct proportions:

    Euston to Chester

    The vertical banding is the result of objects in the forground, such as a lamp posts or telegraph poles, which fill a full frame of video. It should be possible to remove these with some basic image analysis, comparing neighbouring frames and simply dropping any frame that differs too much from previous and subsequent frames.

    The script (which is simply glue around FFmpeg and ImageMagick) can be found on GitHub.