7 use Text::CSV qw( csv );
8 use Data::Dump qw( dump );
10 use Clone qw( clone );
15 my $file = 'keramika.csv';
16 my $aoh = csv (in => $file, headers => "auto");
18 open(my $fh, '>', 'keramika.js');
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} );
27 warn "ERROR: no image $source";
31 #system "convert -trim -geometry 400x $source $image";
32 system qq{convert -fill white -draw "color 1,1 floodfill" -trim -geometry 400x $source $image};
33 #system "convert $image -scale 100x100 -gravity center -background white -extent 100x100 $thumb";
34 system qq{convert $source -fill white -draw "color 1,1 floodfill" -scale 100x100 -gravity center -gravity south -background white -extent 100x100 $thumb};
36 $i->{thumbnail} = $thumb;
37 # $i->{label} = $i->{opis_predmeta};
38 $i->{label} = $i->{ID};
40 foreach my $name ( keys %$i ) {
41 if ( length($i->{$name}) == 0 || $i->{$name} =~ m{^(nema|n/a)$} ) {
46 if ( defined($i->{ukras}) ) {
47 my @ukrasi = split(/\s*,\s+|\s+i\s+/, $i->{ukras});
48 $i->{ukrasi_array} = [ @ukrasi ];
51 if ( defined($i->{očuvan_dio_posude} ) ) {
52 my @ocuvan = split(/\s*,\s+|\s+i\s+/, $i->{očuvan_dio_posude});
53 $i->{ocuvan_array} = [ @ocuvan ];
56 warn "# i = ",dump($i);
57 push @{ $json->{items} }, $i;
58 # foreach my $n ( 1 .. 1000 ) {
60 # $i2->{label} .= "_" . $n;
61 # push @{ $json->{items} }, $i2;
65 print $fh encode_json( $json );