Étiquette : conversion

  • [Debian] Create a QRCode for a vCard file

    Didactic

    I am writing a little tutorial here for creating a QRCode for a vCard file. As I don’t use it that much, it feels like I need a memo for it.

    Preparation

    We will use a vCard file named test.vcf which contains the following:

    Result file

    A vCard image QR encoded
    A vCard QR encoded

    Generating the image

    Prerequisites

    • qrencode package with its dependencies.

    Step by step

    1. In the Terminal, execute the following:

    That’s all! A file named test.vcf.png will be created or overwritten if it already exists.

    If you want to change or get rid of the margin, use the -m option with the size in pixels:

    If you want to change the dots size, use the -s option with the size in pixels:

    Please check the manual if you need more options such as output format (PNG, EPS, SVG, ASCII, etc.).

    Additional Notes

    The same thing with an UI

    You can also use frontends to generate QR encoded files: qtqr package (available on Debian repository) seems interesting.

    vCard syntax

    • If you want to add or remove your own fields, my advice would be to check the properties on the Wikipédia page: https://en.wikipedia.org/wiki/VCard#Properties
    • Make sure to use the right properties for the right vCard version. I am using 2.1 in my example.

    Things to consider to prevent reading failures

    • Make sure the color contrast between the dots and the background is sufficient.
    • Dots should remain dark and the background should remain clear.
    • Make sure the dots are large enough if you want devices with fixed focus (such as my Moto E 1st Gen) to read the image. For instance, the example image was generated with a 4px dot size; 3px dot size was not readable by my Moto E on a 22″ 1920×1080 screen.
    • If you resize your image in a graphics software, it is best to use nearest neighbor interpolation algorithm to preserve sharp dots.
    • If your dot size is 1px, don’t shrink your image as it will lose information. (pretty obvious)
    • Make sure the QR code users will physically have access to the space right in front of the image / print. So don’t put a barrier in front of the image…
  • [Debian] Generate TeX formulas as SVG or PNG images Wikipédia-like

    Preparation

    We will use this file named texfile.tex as the .tex to convert:

    Result file

    PNG demonstration
    PNG demonstration

    Generating PNG images

    Packages you need:

    • texlive (or any other TeX program, I guess)
    • dvipng

    Step by step

    1. In the Terminal, go to the directory containing the .tex file.
    2. Execute this:
      • Output:
    3. Convert to PNG at 150dpi (to get a larger image than default):
      • Output:
    4. Remove the border white spaces of the page and add some borders using imagemagick:
    5. Your file is ready as texfile_trimmed.png.

    Script

    I have made a little script to automatize the conversion, with auto-remove of intermediary files:

    Usage
    1. Save the above script as tex2png, anywhere you want, usually near your .tex files for convenience.
    2. Make it executable: $ chmod +x tex2png.
    3. Syntax: tex2png filename [-keeptempfiles].
      • Example: $ tex2png texfile.tex.
      • Alternatively, you can omit the .tex extension: $ tex2png texfile but I would not recommend it.
      • If you want to keep the intermediary files (dvi, log, etc.), add the -keeptempfiles argument at the end: $ tex2png texfile.tex -keeptempfiles.
    4. The final image is named texfile_trimmed.png

    Generating SVG images

    Packages you need:

    • texlive

    Step by step

    1. In the Terminal, go to the directory containing the .tex file.
    2. Execute this:
      • Output:
    3. Convert to a SVG image with a 1.5 scale factor:
    4. Your file is ready as texfile.svg.

    Remarks

    There is no padding in the SVG method. I have not found yet a method to add a little padding around the figure.

    Also, the --no-fonts is necessary to prevent rendering issues about SVG fonts, especially with Firefox and the default SVG viewer of Debian. So the generated formula will not be selectable as a text, but at least, it will render correctly on every device with SVG support.

    Background

    I needed to include some nice looking formulas on my new game design wiki. I am using MediaWiki but the math add-on was not working on my server (web hosting service, not mine). So I decided to create myself the images offline and upload them as regular image files, so that I don’t need to think too much about trying to set the add-on without having all the privileges I could have on a personal server.