flynx / photobook Goto Github PK
View Code? Open in Web Editor NEWLaTeX class for making photo books.
License: BSD 3-Clause "New" or "Revised" License
LaTeX class for making photo books.
License: BSD 3-Clause "New" or "Revised" License
Hello! Thanks for the package, it looks very interesting!
I would like to try creating travel photo-books with it and I would like to define some multi-image layouts to be used in selected pages. What I mean with it is that, for example, I would like a page to contain four images arranged in a grid, possibly with different sizes. I have started developing the simple command \Collage{outer-margin}{image-spacing}{image-1}{image-2}{image-3}{image-4}
, which can produce something like this:
The white rectangle represents the page produced by LaTeX, while the grey frame is just needed to see the borders of the page.
I managed to build the command, but I am a bit uncertain of the way I did it. I had to create a page and insert 4 cells using "absolute positioning". The width of each image should be (page_width - bleed - 2* outer_margin - image_spacing) / 2
, while the the height (page_height - 2*bleed - 2* outer_margin - image_spacing) / 2
. The origin of the top-left image should be (outer_margin, bleed+outer_margin)
, and for the others I just need to shift one or both origins by image_spacing+image_width
or image_spacing+image_height
.
My doubts are:
\paperwidth
but it is larger than what I expected. Instead, it looks like the proper dimension is \blockwidth
. Is this correct?\bleed
, both horizontally and vertically. I thought the coordinate system started on the top-left corner, but it looks like we need to offset it by this amount. Is my understanding correct?imageblockwidth
used for, etc. I know there's info in the documentation, but I thought I understood them until I saw the results...Here is a minimal (more or less) working example. To compile it, you just need to have an image named test
in the same folder. I used Lenna's picture, it seemed appropriate!
\documentclass[%
layoutmode=block,
blockwidth=20cm,
blockheight=20cm,
imageblockwidth=1.0,
imageblockheight=1.0,
bleed=10mm,
final
]{photobook}
% Remove page numbering
\usepackage{nopageno}
% A font I like
\usepackage{palatino}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The following should eventually be moved into a package
% Dependencies
\usepackage{tikz}
\usepackage{pgfmath}
\usepackage[strict]{changepage}
\usepackage{ifdraft}
% Helper command to convert a value from points to the given unit.
\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
% Print the given length, in cm.
\newcommand{\printcm}[1]{\convertto{cm}{\the#1}cm}
% Create a white box that shows the size (in cm) of the cell it box belongs to.
% This is meant for debugging purposes.
\newcommand{\cellsizebox}{\begin{tikzpicture}\node[draw,minimum width=\cellwidth,minimum height=\cellheight] at (0,0) {\shortstack{W: \printcm{\cellwidth}\\ H: \printcm{\cellheight}}};\end{tikzpicture}}
% Some lengths that I need inside the main macro.
\newlength{\CollageOffset}
\setlength{\CollageOffset}{\bleed}
\newlength{\CollageOuterMargin}
\newlength{\CollageImageSpacing}
\newlength{\CollageFirstWidth}
\newlength{\CollageSecondWidth}
\newlength{\CollageFirstHeight}
\newlength{\CollageSecondHeight}
% Main command: create a collage with four pictures of variable size.
% Usage:
% \CollageTwo{outer_margin}{outer_margin}{width_ratio}{height_ratio}{img1}{img2}{img3}{img4}
%
% Creates a collage with four pictures like this one:
%
% =-----------------------------------+
% = . . . . . . . . . . . . . . . . . |
% = . |
% = . |
% = +------+ +------------+ . |
% = | img1 | | img2 | . |
% = +------+ +------------+ . |
% = . |
% = +------+ +------------+ . |
% = | | | | . |
% = | img3 | | img4 | . |
% = | | | | . |
% = +------+ +------------+ . |
% = . |
% = . |
% = . . . . . . . . . . . . . . . . . |
% =-----------------------------------+
%
% In the image above, the outer frame represents the visible page in the
% produced pdf. The dotted frame is obtained by "shrinking" the page size by
% "\bleed" from all sides, except the gutter. The dotted frame is then shurk,
% this time in all four directions, by a margin equal to "outer_margin". The
% distance between all images is determined by outer_margin. Finally, the size
% of each image is calculated as follows. The remaining horizontal and vertical
% space for the images are respectively:
% W = page_width - bleed - 2*outer_margin - image_spacing
% H = page_width - 2*bleed - 2*outer_margin - image_spacing
% The sizes of the images are then calculated as:
% img1: width_ratio*W ; height_ratio*H
% img2: (1-width_ratio)*W ; (1-height_ratio)*H
% img3: width_ratio*W ; height_ratio*H
% img4: (1-width_ratio)*W ; (1-height_ratio)*H
%
% TODO: allow to set the image fill-type (fit, fill, etc?)
% TODO: key-value pairs with defaults (at least for the ratios!)
% TODO: change name!
\newcommand{\CollageTwo}[8]{%
\begin{page}%
% Give a name to the first two parameters of the macro.
\setlength{\CollageOuterMargin}{#1}%
\setlength{\CollageImageSpacing}{#2}%
%
% Calculate the size of each image using pgfmath.
\pgfmathparse{(\blockwidth - \bleed - 2\CollageOuterMargin - \CollageImageSpacing) * #3}%
\setlength{\CollageFirstWidth}{\pgfmathresult pt}%
\pgfmathparse{(\blockwidth - \bleed - 2\CollageOuterMargin - \CollageImageSpacing) * (1-#3)}%
\setlength{\CollageSecondWidth}{\pgfmathresult pt}%
\pgfmathparse{(\blockheight - 2\bleed - 2\CollageOuterMargin - \CollageImageSpacing) * (#4)}%
\setlength{\CollageFirstHeight}{\pgfmathresult pt}%
\pgfmathparse{(\blockheight - 2\bleed - 2\CollageOuterMargin - \CollageImageSpacing) * (1-#4)}%
\setlength{\CollageSecondHeight}{\pgfmathresult pt}%
%
% Calculate the coordinates of the origins. Make sure to properly handle
% even and odd pages.
\checkoddpage%
\def\collageX{\ifoddpage\else\bleed+\fi \CollageOffset+\CollageOuterMargin}%
\def\collageY{\CollageOffset+\bleed+\CollageOuterMargin}%
\def\collageXX{\collageX+\CollageFirstWidth+\CollageImageSpacing}%
\def\collageYY{\collageY+\CollageFirstHeight+\CollageImageSpacing}%
%
% Place the images if in final mode, or a box with the content size in
% cm, if in draft mode.
\begin{cell}{\collageX,\collageY}{\CollageFirstWidth}{\CollageFirstHeight}%
\ifdraft{\cellsizebox}{\imagecell[fill]{}{#5}}%
\end{cell}%
%
\begin{cell}{\collageXX, \collageY}{\CollageSecondWidth}{\CollageFirstHeight}%
\ifdraft{\cellsizebox}{\imagecell[fill]{}{#6}}%
\end{cell}%
%
\begin{cell}{\collageX, \collageYY}{\CollageFirstWidth}{\CollageSecondHeight}%
\ifdraft{\cellsizebox}{\imagecell[fill]{}{#7}}%
\end{cell}%
%
\begin{cell}{\collageXX, \collageYY}{\CollageSecondWidth}{\CollageSecondHeight}%
\ifdraft{\cellsizebox}{\imagecell[fill]{}{#8}}%
\end{cell}%
\end{page}%
}
% TODO: once the "CollageTwo" macro accepts the defaults for the ratio, remove this macro!
\newcommand{\Collage}[6]{\CollageTwo{#1}{#2}{0.5}{0.5}{#3}{#4}{#5}{#6}}
% Book information
\def\BookTitle{Foobar}
\def\BookAuthors{Franco Fusco}
\def\ThanksTo{Flynx}
\def\Edition{N/A}
\begin{document}
% Author and copyright information.
\BookInfoPage
% "Square" aspect ratio
\Collage{0cm}{0cm}{test}{test}{test}{test}
\Collage{0cm}{0.5cm}{test}{test}{test}{test}
\Collage{1cm}{0cm}{test}{test}{test}{test}
\Collage{1cm}{0.5cm}{test}{test}{test}{test}
% Non-square aspect ratio
\CollageTwo{0cm}{0cm}{0.6}{0.6}{test}{test}{test}{test}
\CollageTwo{0cm}{0.5cm}{0.6}{0.6}{test}{test}{test}{test}
\CollageTwo{1cm}{0cm}{0.6}{0.6}{test}{test}{test}{test}
\CollageTwo{1cm}{0.5cm}{0.6}{0.6}{test}{test}{test}{test}
% Full bleed
\CollageTwo{-\bleed}{0cm}{0.6}{0.6}{test}{test}{test}{test}
\CollageTwo{-\bleed}{0.5cm}{0.6}{0.6}{test}{test}{test}{test}
\end{document}
Hello,
Very good idea ! Thanks a lot for this new class. I'm a photographer and I always dreamed of making professionnal photo books in Linux, using Latex, without spending hours and hours...
Reading the documentation, I have not fully understand (yet) how to easely make pages (or double pages) with multiples photos and captions on the same page.
Would it be possible to add au bunch of page templates to the photobook class, with different page layouts like :
I'd like to thank you for the gift you've given us.
Could you provide us templates of book using photobook. This will be greatfull.
Thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.