Wikipedia:WikiProject Chemistry/Structure drawing workgroup/Mysid's script: Difference between revisions

Content deleted Content added
Note on bug.
Yes, a blur effect solves the problem with missing things that are separated by blank space.
Line 98:
$he = $img->Get('height');
$wi = $img->Get('width');
#Blur the image so that we don't miss the edge later on, and to make a nice
#border...
$x = $img->Blur(geometry=>'5.0x5.0', sigma=>5.0, radius=>5.0, channel=>"All");
print "$x\n";
$img->Write(filename=>'test.png');
 
 
print STDERR "crop...\n";
Line 104 ⟶ 110:
#read the file one pixel row at a time, always starting at the edge value
#detected, going outwards until we hit a completely empty line (pure
#transparent pixels) This seems to work for all BKchem files, but would of
#course fail for general SVG files.
#BUG:This works for most BKchem files, but is broken by text with gaps at the
#edge. Maybe a nice fat gaussian blur will fix this and make an automatic
#border...
for ($y=$maxy; $y<$he; $y++) {
@row = $img->GetPixels(width=>$wi, height=>1, x=>1, y=>$y, map=>'RGBA');
Line 158 ⟶ 162:
}
 
$w=($maxx-$minx+($maxx*0.05));
#Make a border around the image, 5% wide. Seems a bit narrow to me, not sure
$h=($maxy-$miny+($maxy*0.05));
#why.
$w=($maxx-$minx+($maxx*0.05));
$h=($maxy-$miny+($maxy*0.05));
 
$outfilename = $ARGV[0];
Line 168 ⟶ 170:
 
open INPUT,"<$ARGV[0]_tmp.svg";
#$firstgroupflag=0;
while (<INPUT>) {
if(/<svg .*viewBox="0 0 \d+ \d+"/) {