GeneralIs this possible in LaTeX ? (random pictures in background)

LaTeX specific issues not fitting into one of the other forums of this category.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Cham »

I'm wondering about an idea for a travel journal with a fancy background texture rendering (imagine an old book made of some deteriorated paper). Is the following idea possible, in LaTeX ? If so, how ?

Here's a MWE for a journal with a generic background texture, one for the odd pages and another one for the even pages (I commented out the textures so the code could compile here) :

Code: Select all

\documentclass[12pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{anysize}
\marginsize{1.0in}{1.0in}{0.5in}{0.5in}
\usepackage[]{hyperref}
\usepackage{eso-pic}
\usepackage{changepage}
\strictpagecheck
\usepackage{blindtext}

\begin{document}

\AddToShipoutPicture{\checkoddpage
   \ifoddpage
	%\put(0,0){\includegraphics[width=\paperwidth,height=\paperheight]{Textures/odd_page.jpg}}
   \else
	%\put(0,0){\includegraphics[width=\paperwidth,height=\paperheight]{Textures/even_page.jpg}}
   \fi
	}

\Blinddocument
\end{document}
Now the idea is this : I would like to add some random details to the background, so all the pages are rendered with an almost unique aspect. The details would be some small pictures to be randomly placed on each corner of the page (folded corner), and also some other graphics are randomly distributed on the page (dirt, spots, random marks,... bounded by some region on the page so the random marks don't interfere with the folded corners).

Some pages could render without any details added, some other pages would have a single folded corner, some other pages would have both corners folded, etc.

I don't know if my idea is well described (sorry, English isn't my native language).

I guess that each LaTeX compilation would give a different output. I don't think this is a problem.

Any idea about how to implement this ?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Stefan Kottwitz »

Sure, there's a TeX command for conditional expressions, such as

Code: Select all

\ifcase<integer number>
  % case 0
\or
  % case 1
\or
...
\else% optional
  % optional case
\fi
For example TikZ provides random numbers. Have a look at the random Tikz examples in the gallery. Once an integer random is generated, you can work with \ifcase. Perhaps you also like that torn paper example.

Well, it might be easier to print on nice paper, and manipulate it so it looks older. A computer generated effect might not look so real.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Is this possible in LaTeX ? (random pictures in backgrou

Post by Cham »

Stefan,

could you give a complete example from the code above, how to make a folded corner, randomly distributed on all the pages ? It's really not obvious to me.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Is this possible in LaTeX ? (random pictures in backgrou

Post by Stefan Kottwitz »

Well, what's the point in the moment? The random thing? Or as a start, kind of a folded corner? It could be good to split such a big task into problems with a more handy size. Smaller separate problems could easier be solved than complex projects where reader's hardly know, where to start.

Here, the topic was random background pictures. How about starting a new topic, specifically for how creating a folded corner, with an exact description what to achieve for this specific issue?

Always feel free to open new topics. It's much easier to work with and to read. Long threads don't help in organizing. Don't worry about a number of topics.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Is this possible in LaTeX ? (random pictures in backgrou

Post by Cham »

Well, about the folded corners, I'm curious to see what LaTeX is able to do. In the Tikz examples page, I didn't found an example about corners of the page. Anyway, I doubt that a LaTeX generated corner would be satisfying.

The random use of pictures on the corners is probably the best option, but I don't know at all how to implement this.

My intention was to create a set of pictures of real looking folded corners (with shadows and textures...), then tell LaTeX to paste the pictures on the corners of the page, with a random setting (so the pages don't get the same picture on all corners, and to let many pages to have normal corners).
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Stefan Kottwitz »

Well, you could create such a set of pictures and post it as attachments here. I'm sure somebody, possibly including me, would show a way to include them randomized. TeX people, who would join to help, just need something to work with, such sample material. The more realistic, the more enjoyable, so it makes fun to join the effort. (A formula is better than the word "bla", a real image better than a black square).

Btw. here's a corner example: Exam sheet. Could be combined with a TikZ decoration with random steps.

Also an idea regarding your images: once you have images, they can be placed in a "fading" way, to get a smooth transition from the page to the image.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Cham »

Here's a picture of the actual corners of my journal. I've indicated in red the places where I would like to paste a random picture to add the folded corners :
corners.jpg
corners.jpg (40.2 KiB) Viewed 10187 times
Currently, the background is a texture to simulate some old paper (see the code in my first post above).

The folded corners aren't created yet, since I'm not even sure that I'll be able to do the LaTeX code. I intend to create some test pictures today or tomorrow.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Is this possible in LaTeX ? (random pictures in backgrou

Post by Stefan Kottwitz »

Great, just post your sample corners and the texture image files here then, for testing.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Cham »

Here we go.

The generic background textures defined in my code above are these (to be located inside a "Textures" folder) :

Odd pages :
odd_page.jpg
odd_page.jpg (98.4 KiB) Viewed 10170 times
Even pages :
even_page.jpg
even_page.jpg (99.73 KiB) Viewed 10170 times
Now, just for testing purposes, I've created a cheap set of four corners (I know that they are very ugly. They are just temporary pictures for testing purposes only) :

Two corners for the odd pages :
odd_down1.jpg
odd_down1.jpg (7.83 KiB) Viewed 10170 times
odd_up1.jpg
odd_up1.jpg (7.95 KiB) Viewed 10170 times
Two corners for the even pages in my next post (max allowed is 4 pictures per post) :
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Is this possible in LaTeX ? (random pictures in background)

Post by Cham »

Two pictures for the corners on the even pages :
even_down1.jpg
even_down1.jpg (8.06 KiB) Viewed 10169 times
even_up1.jpg
even_up1.jpg (8.05 KiB) Viewed 10169 times
The number "1" in the pictures name is the random variable. There would be more pictures like these :

even_up1.jpg, even_up2.jpg, even_up3.jpg, ...

etc.

Take note that some pages shouldn't have any pictures pasted in the corners (normal corner).

EDIT 1 : Hmm, I may have goofed on the small textures posted here. They wont fit well with the background textures, but again these aren't the final pictures. Just a quick and dirty set (made in 1 minute !). I'll post a better set here later. Creating some good looking textures takes a lot of time.

EDIT 2 : The small pictures could be in PNG format with some transparency, to blend better on the background. There are several ways in doing this. Currently, I'll use JPG, made from the main background textures.

Creating the textures takes a lot of time, since I want to achieve a realistic effect with shadows. This is the hardest part of the project.
Last edited by Cham on Thu Jul 31, 2014 6:41 pm, edited 1 time in total.
Post Reply