Code Monkey home page Code Monkey logo

photobook's People

Contributors

flynx avatar muzimuzhi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

photobook's Issues

Creating a multi-picture layout

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:

collage

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:

  • To obtain the width of the page, I tried using \paperwidth but it is larger than what I expected. Instead, it looks like the proper dimension is \blockwidth. Is this correct?
  • When I calculate the origin of the first picture, it looks like there is "something" missing in my calculations. After experimenting a bit, I think that my conclusion is that the origin has to be offset by \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?
  • I guess in general it's not clear to me what are the dimensions to use in general, and what they signify. As an example, why is paperwidth larger than the pdf size, what is 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}

Thanks !!! And new feature proposal...

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 :

  • A page template with 2 pictures side by side, verticaly, or horizontaly
  • A page template with 2 pictures in diagonal (left-Top and right-bottom, and the opposite) ,
  • idem with 3, 4, 5, 6 and more pictures in a page...
  • etc...
    Do you think it is feasible ? Thanks !

Examples

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.