How to mass crop the front image of a dvd cover v2.2

  • Throughout the month of April 2024, participate in the FileJoker Thread Contest OPEN TO EVERYONE!

    From 1st to 30th of April 2024, members can earn cash rewards by posting Filejoker-Exclusive threads in the Direct-Downloads subforums.

    There are $1000 in prizes, and the top prize is $450!

    For the full rules and how to enter, check out the thread
  • Akiba-Online is sponsored by FileJoker.

    FileJoker is a required filehost for all new posts and content replies in the Direct Downloads subforums.

    Failure to include FileJoker links for Direct Download posts will result in deletion of your posts or worse.

    For more information see
    this thread.

SamKook

Grand Wizard
Staff member
Super Moderator
Uploader
May 10, 2009
3,565
4,943
This is a way to crop dvd covers from your collection using script-fu(a script feature of gimp(a free image editor)) to use the front as thumbnails in other applications(like XBMC).

This may not be usefull to many(if it is to some at all other than me), but I thought I should post it, just in case.

Here's an example of the result:

[FULLATTACH]325535[/FULLATTACH]

Requirements:
-The gimp v2.6 or higher(v2.6.4 is the lowest I tested this with)
-The cover must be a jpeg(.jpg)
-Having the cover named the same as the folder they are in(except for the .jpg). Works best if the dvd code is used.
-Having basic knowledge of windows or linux and being able to follow instructions.

Here's an example of how my collection is set up and the content of a folder. The only important thing for this to work is that the cover must be named the same as the folder. The rest of the folder content is of no importance.

[FULLATTACH]325536[/FULLATTACH]

Windows:
First, you need to create a .txt file that will contain the script(I named mine "crop_cover_folders.txt"). Copy the following code, paste it in the .txt and save it.

Code:
(define (crop_cover path)
(let* (
(dirlist (dir-open-stream (string-append path "/")))
(company)(input)(output)(image)(width)(height)(q)(x)(zmod)(y)(z)(drawable)(currentdir)
)

(while (not (eof-object? (set! currentdir (dir-read-entry dirlist))))
(if (= (file-type (string-append path "/" currentdir)) 2)
(begin
(set! input (string-append path "/" currentdir "/" currentdir ".jpg"))
;Verify if it's a valid folder for a cover
(if (file-exists? input)
(begin
(set! output (string-append path "/" currentdir "/folder.jpg"))
(set! company (substring currentdir 0 4))
(set! image (car (file-jpeg-load 1 input output)))
(set! width (car (gimp-image-width image)))
(set! height (car (gimp-image-height image)))
;Read value of parasite "jpeg-settings", get quality setting, change from ascii to integer, change to float, put in variable "q"
(set! q (/ (char->integer (string-ref (caddr (car (gimp-image-parasite-find image "jpeg-settings"))) 1)) 100.0))

;Preset SOD (SDMS, SDDE) [1024x686] crop 3 pixels
(if (or (equal? company "SDMS") (equal? company "SDDE") (equal? company "SDMT"))
(begin (set! height (- height 5)) (set! y 2) (set! zmod 0))

;Preset Natura High (NHDT) [1024x687,686,684] crop 2 pixels
(if (equal? company "NHDT")
(begin (set! height (- height 3)) (set! y 1) (set! zmod 0))

;Preset HTY [780x525] crop 1 pixel
(if (equal? company "HTY-")
(begin (set! height (- height 2)) (set! y 1) (set! zmod 0))

;Preset Prestige (EVO, DAY, ZER, EZD, DOM) [777x522] crop 1 pixel
(if (or (equal? company "EVO-") (equal? company "DAY-") (equal? company "ZER-") (equal? company "EZD-") (and (equal? company "DOM-") (= height 522)))
(begin (set! height (- height 2)) (set! y 1) (set! zmod 0))

;Preset Prestige (DOM) [777x488] overcrop a little
(if (and (equal? company "DOM-") (= height 488))
(begin (set! y 0) (set! zmod 40))

;Preset DIM [~700x470] crop 5 pixels
(if (equal? company "DIM-")
(begin (set! height (- height 7)) (set! y 2) (set! zmod 0))

;Preset DNPD front on the left, crop 0 pixels
(if (equal? company "DNPD")
(begin (set! y 0) (set! zmod (- width (trunc (+(* height .71) 9)))))

;Preset CRZ [800x541] crop 5 pixels
(if (and (equal? company "CRZ-") (= height 541))
(begin (set! height (- height 7)) (set! y 2) (set! zmod 0))

;Preset FSET [1000x675] crop 2 pixels
(if (and (equal? company "FSET") (= height 675))
(begin (set! height (- height 3)) (set! y 1) (set! zmod 0))

;Preset Natural High (ABC-001) [1024x689]
(if (and (equal? company "ABC-") (= height 689))
(begin (set! height (- height 108)) (set! y 108) (set! zmod 46))

;Preset Moodyz (MIRD dual discs) [800x499] center the overcropping
(if (and (equal? company "MIRD") (= height 499))
(begin (set! y 0) (set! zmod 5))

;Preset Opera (OPRD) [800x540] crop 1 pixel
(if (and (equal? company "OPRD") (= height 540))
(begin (set! height (- height 1)) (set! y 0) (set! zmod 0))

;Preset Jade (P9) [700x470] crop 2 pixels
(if (and (equal? company "P9-0") (= height 470))
(begin (set! height (- height 3)) (set! y 3) (set! zmod 0))

;Preset Rocket (RCT) [700x471] crop 2 pixels
(if (and (equal? company "RCT-") (= height 471))
(begin (set! height (- height 3)) (set! y 3) (set! zmod 0))

;Preset Image (SIMG) [1280x864] crop 10 pixels
(if (and (equal? company "SIMG") (= height 864))
(begin (set! height (- height 14)) (set! y 7) (set! zmod 0))

;Preset Image (SIMG) [800x541] crop 4 pixels
(if (and (equal? company "SIMG") (= height 541))
(begin (set! height (- height 5)) (set! y 3) (set! zmod 0))

;Preset Image (SVDVD) [950x636] crop 2 pixels
(if (and (equal? company "SVDV") (= width 950))
(begin (set! height (- height 3)) (set! y 1) (set! zmod 0))

;Preset Image (XV-65) [750x509] crop 6 pixels
(if (and (equal? company "XV-6") (= width 750))
(begin (set! height (- height 9)) (set! y 4) (set! zmod 0))

;Preset (DVDES) [750x503] crop 2 pixels
(if (and (equal? company "DVDE") (= width 750))
(begin (set! height (- height 3)) (set! y 1) (set! zmod 0))

;Preset [800x538] crop 2 pixels
(if (and (= height 538) (= width 800))
(begin (set! height (- height 3)) (set! y 1) (set! zmod 0))

;Preset [800x537] crop 1 pixel
(if (and (= height 537) (= width 800))
(begin (set! height (- height 1)) (set! y 0) (set! zmod 0))

;Default preset: Anna & Hanako (ANND) [800x536], Hayabusa (AMZ) [900x600] crop 0 pixels
(begin (set! y 0) (set! zmod 0))
)))))))))))))))))))))

;Calculate width of cropped image
(set! x (trunc (-(* height .71) 1)))
;Calculate the width of the area to remove
(set! z (- width x))
;Crop image
(gimp-image-crop image x height (- z zmod) y)
;Example si on veut setter une variable en dehors de la declaration(it wasn't necessary in this case)
(set! drawable (car (gimp-image-get-active-drawable image)))
;Save in jpeg
(file-jpeg-save 1 image drawable output output q 0 1 0 "" 0 1 0 0))))))
(dir-close-stream dirlist)))

;Set the folder(s) to be cropped(the / at the end can be ommited or not)
;(crop_cover "")
(crop_cover "D:/JAV")

(gimp-quit 0)

The only thing you need to change is the path of the jav folder you want to crop the covers of. Replace the D:/JAV with you own folder in this line: "(crop_cover "D:/JAV")".
This will search for all the .jpg named the same as all the folders at that path and will ignore the folders with no .jpg named the same as them inside.
If you want to do more than one folder at once, you can copy that line, paste it to the next and put another path. You can do that as many times as you want.

Next, you need to create a .bat to execute the script(or just write in in a cmd window(don't write the "@echo off" if you do that)). Create a .txt and put this code in it:
Code:
@echo off
"C:\Program Files\Gimp-2.0\bin\gimp-console-2.6" -i -b - < ./crop_cover_folders.txt
You may need to change the path of your gimp install and if you use v2.7 or higher, you also need to change the name of gimp-console to the one from your installation. If you didn't name the script the same as me, you also need to change that.

After all this is done, rename this .txt to .bat(you need to have windows show the file extension for that) and double-click it to execute it. It will open a black cmd windows that will close when the script finishes its job. It will create a file called folder.jpg in every folder where a cover was found.

Note: It will overwrite any file named folder.jpg in the folders where it detects a cover without asking.


Linux:
The only difference for linux is that instead of a .bat file, you need to create a .sh file and add the following in it:

Code:
gimp-console -i -b - < ./crop_cover_folders.txt


Advanced modifications section:

The script should work with most sizes, but since not all covers on the internet have the exact same ratio, the cropping may not be perfect in certain cases since it keep a fixed ratio for the dimensions of the new file(0.71).
If this is the case for some company or source, you can fine tune the cropping using a preset(see the many examples from the current script).
A preset changes the default cropping settings for all covers that start with the 4 characters specified.

Add a new preset:(presets are only useful if the file is not cropped enough, you can't fix an over-cropped file):
You need to copy the following code and paste it on the next line right after any preset(or on a new line right before the ;Default preset).

Note: If you add more than one preset, the important thing is to always add them before the ;Default preset.

Code:
;Preset Some_name some_description
(if (equal? company "First_4_letters")
(begin (set! height (- height 5)) (set! y 2) (set! zmod 0))

The line starting with a ";" is a comment and you don't really need it.
You need to change the "First_4_letters" to the first 4 characters of the cover you want to create a preset to(if the file is FSD-09.jpg, you need to put "FSD-").

If you want more than one "company" to use the same preset, do it like this:

Code:
(if (or (equal? company "SDMS") (equal? company "SDDE"))

Next you need to do the adjusments.

Change the "height" value(5 in the example) to the number of pixels to crop from the width divided by .71 and round up to the next integer(in this case, it crops 3 pixels which would give 4.22 that you round up to 5).

If you crop the width in a preset, the height will also be cropped more from the bottom. The "y" value(2 in the example) is the number of pixels to crop at the top instead of the bottom(it moves the cropping area, it doesn't shrink it).
The number of cropped pixels from the height is the "height" value(the number you replaced 5 with), so the best default value instead of 2 is half of the "height" value.

The "zmod" values is only usefull if you want to move the cropped area to the left. For example, if there were a white line of 2 pixels at the right of the picture, you could change the "zmod" value(0 in the example) to 2 and the white wouldn't show up.

You also need to add a ")" after the bunch of ")" after the default preset for every preset you add.
For example, if there were only 3 presets, it would look like this:

Code:
;Default preset: Anna & Hanako (ANND) [800x536], Hayabusa (AMZ) [900x600] crop 0 pixels
(begin (set! y 0) (set! zmod 0))
)))


Suggestions?
If some part is not clear enough, if I made a mistake or if you have an amelioration to suggest, let me know.


Changes history:
v2.2: - Added a bunch of presets(it should make the script a lot more compatible now. I can do my whole collection automatically with it)
- Added the zmod variable to make the presets more flexible.
- Explained the zmod variable and change the explanations for the other variables a bit.

v2.1: - Added how to use more than one company with the same preset settings

v2: -Fixed the add preset procedure
-Added procedure for linux

v1: -Added procedure for windows
 
  • Like
Reactions: 2 people

chippy

Satyagrahi
Feb 10, 2008
222
38
SamKook,

Haven't downloaded it, don't need it, and I clicked the button already, but I just HAD to post to really say Thank You! It's well-explained, thorough and cross-platform tutorials like yours that we need MUCH more of in this section. I won't be using it, but I *really* appreciate this contribution!