projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Volltext-Suche: Hintergrund-Job: POD
[kivitendo-erp.git]
/
scripts
/
image_maps.pl
diff --git
a/scripts/image_maps.pl
b/scripts/image_maps.pl
index
0329481
..
f0471d6
100755
(executable)
--- a/
scripts/image_maps.pl
+++ b/
scripts/image_maps.pl
@@
-1,15
+1,16
@@
#!/usr/bin/perl
use strict;
#!/usr/bin/perl
use strict;
-use GD;
use Getopt::Long;
use File::Basename;
use Getopt::Long;
use File::Basename;
-
my $css_file = 'generated.css';
my $image_file = 'generated.png';
my $class_for_map = 'icon';
my $css_file = 'generated.css';
my $image_file = 'generated.png';
my $class_for_map = 'icon';
+my $convert_bin = 'convert';
+my $identify_bin = 'identify';
+
GetOptions(
'css-out=s' => \$css_file,
'image-out=s' => \$image_file,
GetOptions(
'css-out=s' => \$css_file,
'image-out=s' => \$image_file,
@@
-17,76
+18,74
@@
GetOptions(
);
my @files = @ARGV;
);
my @files = @ARGV;
-my @gd_images;
-
-GD::Image->trueColor(1);
+my @images;
# read files
# read files
-for my $filename (@files) {
-
my $image = GD::Image->newFromPng($filename)
;
+for my $filename (
sort
@files) {
+
my $image = `$identify_bin $filename`
;
if (!defined $image) {
if (!defined $image) {
- warn "warning: could not
load image '$filename'. sk
pping...";
+ warn "warning: could not
identify image '$filename'. ski
pping...";
next;
}
next;
}
- push @gd_images, {
- gd => $image,
+ $image =~ /^(?<filename>\S+) \s (?<type>\S+) \s (?<width>\d+) x (?<height>\d+)/x;
+ push @images, {
filename => $filename,
filename => $filename,
+ type => $+{type},
+ width => $+{width},
+ height => $+{height},
};
}
# make target layout
# for simplification thi will check if all the images have the same dimensions
# and croak if not
};
}
# make target layout
# for simplification thi will check if all the images have the same dimensions
# and croak if not
-my $first_height = $
gd_images[0]->{gd}->height
;
-my $first_width = $
gd_images[0]->{gd}->width
;
+my $first_height = $
images[0]->{height}
;
+my $first_width = $
images[0]->{width}
;
use Data::Dumper;
use Data::Dumper;
-for my $img (@
gd_
images) {
- die 'heights are not equal' if $first_height != $img->{
gd}->height
;
- die 'widths are not equal' if $first_width != $img->{
gd}->width
;
+for my $img (@images) {
+ die 'heights are not equal' if $first_height != $img->{
height}
;
+ die 'widths are not equal' if $first_width != $img->{
width}
;
}
# all equal? nice.
# we'll be lazy and just put them all together left-to-right
my $new_height = $first_height;
}
# all equal? nice.
# we'll be lazy and just put them all together left-to-right
my $new_height = $first_height;
-my $new_width = $first_width * @
gd_
images;
+my $new_width = $first_width * @images;
-my $new_image = GD::Image->new($new_width, $new_height, 1);
# now copy them all together, and keep a referende to;
# now copy them all together, and keep a referende to;
-$new_image->saveAlpha(1);
-$new_image->alphaBlending(0);
+my $convert_string = "$convert_bin ";
my $h_offset = 0;
my $h_offset = 0;
-for (@
gd_
images) {
+for (@images) {
$_->{h_offset} = $h_offset;
$_->{v_offset} = 0;
$_->{h_offset} = $h_offset;
$_->{v_offset} = 0;
- $
new_image->copy($_->{gd}, $_->{h_offset}, $_->{v_offset}, 0, 0, $_->{gd}->width, $_->{gd}->height)
;
+ $
convert_string .= ' +append ' . $_->{filename}
;
} continue {
} continue {
- $h_offset += $_->{
gd}->width
;
+ $h_offset += $_->{
width}
;
}
}
+$convert_string .= " -background none +append $image_file";
+
# now write that png...
# now write that png...
-{
- open my $file, '>:raw', $image_file or die "can't write to $image_file";
- print $file $new_image->png;
-}
+system($convert_string);
# make css file
{
open my $file, ">", $css_file or die "can't write too $css_file";
print $file ".$class_for_map { background: url(../$image_file) ${first_width}px 0px no-repeat; padding: 0; width: ${first_width}px; height: ${first_height}px; }\n";
# make css file
{
open my $file, ">", $css_file or die "can't write too $css_file";
print $file ".$class_for_map { background: url(../$image_file) ${first_width}px 0px no-repeat; padding: 0; width: ${first_width}px; height: ${first_height}px; }\n";
- for (@
gd_
images) {
+ for (@images) {
my $name = fileparse($_->{filename}, ".png");
# the full grammar for valid css class names is completely bonkers (to put it mildly).
my $name = fileparse($_->{filename}, ".png");
# the full grammar for valid css class names is completely bonkers (to put it mildly).
- # so instead of trying to punch filenames into those class names, we'll
just reduce them to a nice minimal set of
- #
a-z _ -
+ # so instead of trying to punch filenames into those class names, we'll
+ #
just reduce them to a nice minimal set of lower case /[a-z0-9_-]*/
$name = lc $name;
$name = lc $name;
- $name =~ s/[^a-z_-]/-/g;
+ $name =~ s/[^a-z
0-9
_-]/-/g;
print $file ".$class_for_map.$name { background-position: -$_->{h_offset}px 0px; }\n";
}
}
print $file ".$class_for_map.$name { background-position: -$_->{h_offset}px 0px; }\n";
}
}