convert new images, fill background
[keramika-neolitik] / csv2js.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 use Text::CSV qw( csv );
8 use Data::Dump qw( dump );
9 use JSON;
10 use Clone qw( clone );
11 use autodie;
12
13 use utf8;
14
15 my $file = 'keramika.csv';
16 my $aoh = csv (in => $file, headers => "auto");
17
18 open(my $fh, '>', 'keramika.js');
19 my $json;
20
21 foreach my $i ( @$aoh ) {
22         my $source = sprintf( "../ZBIRKA-NEOLITIK/%d.png", $i->{ID} );
23         my $image = sprintf( "image/%d.jpg" , $i->{ID} );
24         my $thumb = sprintf( "thumb/%d.jpg" , $i->{ID} );
25
26         if ( ! -e $source ) {
27                 warn "ERROR: no image $source";
28                 next;
29         }
30
31         system "convert -trim -geometry 400x $source $image";
32         #system "convert $image -scale 100x100 -gravity center -background white -extent 100x100 $thumb";
33         system qq{convert $source -fill white -draw "color 1,1 floodfill" -scale 100x100 -gravity center -background white -extent 100x100 $thumb};
34         $i->{image} = $image;
35         $i->{thumbnail} = $thumb;
36 #       $i->{label} = $i->{opis_predmeta};
37         $i->{label} = $i->{ID};
38
39         my @ukrasi = split(/\s*,\s+|\s+i\s+/, $i->{ukras});
40         $i->{ukrasi_array} = [ @ukrasi ];
41
42         my @ocuvan = split(/\s*,\s+|\s+i\s+/, $i->{očuvan_dio_posude});
43         $i->{ocuvan_array} = [ @ocuvan ];
44
45         warn "# i = ",dump($i);
46         push @{ $json->{items} }, $i;
47 #       foreach my $n ( 1 .. 1000 ) {
48 #               my $i2 = clone $i;
49 #               $i2->{label} .= "_" . $n;
50 #               push @{ $json->{items} }, $i2;
51 #       }
52 }
53
54 print $fh encode_json( $json );
55 close($fh);
56