Re: using make to convert images to thumbs
On Sun, 2006-02-26 at 12:49 -0500, Dave Johnson wrote: > thumb/%: % > Why couldn't I see that? I must have a monkey-see-monkey-do sort of brain. I was just hung up on suffixes (which are both .jpg) and more exotic patterns. The Makefile works great. Thanks very much to all. -- Lloyd Kvam Venix Corp ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: using make to convert images to thumbs
Dave Johnson writes: > Python writes: > > I have a client that laid out their images and thumbs into almost > > parallel directory structures. > > /img/thumb > > /x /img > > /y /x > > /*.jpg /y > > /*.jpg > > > > x and y are two digit directory names used to shorten the directory > > scans to retrieve files. I thought I could use a Makefile to automate > > the creation of thumbs, but this pattern has me stumped. > > > > I am going to just write a script to step through the source tree and > > check the corresponding time stamp unless someone offers a suggestion. > > (No they will not shuffle things around because they have lots of logic > > in place.) > > slightly improved clean rule: -- Dave .DEFAULT: all .DELETE_ON_ERROR: .PHONY: all clean IMAGES=$(wildcard img/*/*/*.jpg) THUMBS=$(patsubst %,thumb/%,$(IMAGES)) all: $(THUMBS) thumb/%: % @mkdir -p $(@D) convert $^ -scale 160x120 -quality 25 $@ clean: $(RM) -r thumb ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: using make to convert images to thumbs
Python writes: > I have a client that laid out their images and thumbs into almost > parallel directory structures. > /img/thumb > /x /img > /y /x > /*.jpg /y > /*.jpg > > x and y are two digit directory names used to shorten the directory > scans to retrieve files. I thought I could use a Makefile to automate > the creation of thumbs, but this pattern has me stumped. > > I am going to just write a script to step through the source tree and > check the corresponding time stamp unless someone offers a suggestion. > (No they will not shuffle things around because they have lots of logic > in place.) here you go: .DEFAULT: all .DELETE_ON_ERROR: .PHONY: all clean IMAGES=$(wildcard img/*/*/*.jpg) THUMBS=$(patsubst %,thumb/%,$(IMAGES)) all: $(THUMBS) thumb/%: % @mkdir -p $(@D) convert $^ -scale 160x120 -quality 25 $@ clean: $(RM) $(THUMBS) -- Dave ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: using make to convert images to thumbs
Not that using "make" won't work, but I don't see the advantage of the approaches being discussed versus a simple shell script. make is cool because it allows you to describe arbitrarily complex dependency relationships between various objects so that it can analyze those relationships to determine whether any actions are necessary to keep those relationships current. But it sorta looks like the approach just suggested simply launches an instance of bash for every target, with bash doing ALL the work, so why not just express that same logic in a simple shell script and dispense with make entirely? If you're really committed to using make, you might consider generating one giant rules file using a shell script that sweeps through the directory(s) in question and then feed those rules to make, maybe something like this: cd IMAGE_DIR for f in $( find . -type f ) do echo "$THUMB_DIR/$f:$IMAGE_DIR/$f" >> /tmp/makefile done make -f /tmp/makefile ...with maybe some kind of implicit rule along the lines of the .c.o rule to control the necessary action(s). Just a thought, FWIW, YMMV, IANAL, IMHO, etc... ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: using make to convert images to thumbs
Jason Stephenson wrote: ## Makefile example starts here. ## IMG_BASE = /img THM_BASE = /thumb/img IMG_PROC = /path/to/image/processor IMG_PROC_OPTS = # default options for image processor TARGET = # undefined. define on command line thumbs: if test "${TARGET}" = "" ; then echo "TARGET undefined" else ${IMG_PROC} ${IMG_PROC_OPTS} ${IMG_BASE}/${TARGET} \ ${THM_BASE}/${TARGET} fi ## Makefile example ends here. ## There are errors in the above Makefile example. One that would actually run through make would like this: ## Makefile example starts here. ## IMG_BASE = /img THM_BASE = /thumb/img IMG_PROC = /path/to/image/processor IMG_PROC_OPTS = # default options for image processor TARGET = # undefined. define on command line thumbs: if test "${TARGET}" == "" ; then \ echo "TARGET undefined" \ else \ ${IMG_PROC} ${IMG_PROC_OPTS} ${IMG_BASE}/${TARGET} \ ${THM_BASE}/${TARGET} \ fi ## Makefile example ends here. ## I noticed them after I sent the email. Unfortunately, I don't pay as much attention when typing code in an email than when actually doing something that I'm going to try to use. ;) ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: using make to convert images to thumbs
Python wrote: I have a client that laid out their images and thumbs into almost parallel directory structures. /img/thumb /x /img /y /x /*.jpg /y /*.jpg x and y are two digit directory names used to shorten the directory scans to retrieve files. I thought I could use a Makefile to automate the creation of thumbs, but this pattern has me stumped. How so? It is very straightforward. I'd put the Makefile in the /img directory or just above it. Your target to make the thumbnails would run whatever program makes the thumbnails with the appropriate options. If you needed different target directories, you could specify them in the environment and on the command line. BSD make makes this trivial and I'm pretty sure that GNU Make works about the same. Here's an example: The Makefile: ## Makefile example starts here. ## IMG_BASE = /img THM_BASE = /thumb/img IMG_PROC = /path/to/image/processor IMG_PROC_OPTS = # default options for image processor TARGET = # undefined. define on command line thumbs: if test "${TARGET}" = "" ; then echo "TARGET undefined" else ${IMG_PROC} ${IMG_PROC_OPTS} ${IMG_BASE}/${TARGET} \ ${THM_BASE}/${TARGET} fi ## Makefile example ends here. ## Then, on the command line, you might run: $ make thumbs TARGET=x/y The above should work with BSD make, and I'm 90% certain that it will work with GNU make, as well. It might require a little massage to actually do anything useful. I am going to just write a script to step through the source tree and check the corresponding time stamp unless someone offers a suggestion. (No they will not shuffle things around because they have lots of logic in place.) That would work if you have it run periodically and just make thumbs for new files, or files that have changed. My example above could be used to do entire subdirectories at once. If you know much about make, there are ways to make the above fancier and more bulletproof. For instance, you might want to have IMG_PROC_OPTS be added to what is specified in the environment rather just being hardcoded in the Makefile or completely overridden by the command line environment. This would make it easier to have slightly different options on a given run. Also, if you need to specify filenames or globs to the IMG_PROC, you can do that as part of your target. My assumption above is that the IMG_PROC can take directories as targets and processess everything in them.--Perhaps it is a script. Along the same lines, a fancier solution would run a shell loop over the files in the TARGET directory, and process each one with IMG_PROC if you don't have a script to do everything in a directory in one go. HtH, Jason ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
using make to convert images to thumbs
I have a client that laid out their images and thumbs into almost parallel directory structures. /img/thumb /x /img /y /x /*.jpg /y /*.jpg x and y are two digit directory names used to shorten the directory scans to retrieve files. I thought I could use a Makefile to automate the creation of thumbs, but this pattern has me stumped. I am going to just write a script to step through the source tree and check the corresponding time stamp unless someone offers a suggestion. (No they will not shuffle things around because they have lots of logic in place.) -- Lloyd Kvam Venix Corp ___ gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss