User:AndyE: Difference between revisions
From London Hackspace Wiki
threshold
mNo edit summary |
(threshold) |
||
| Line 13: | Line 13: | ||
The Landy [[File:AndysLandy.JPG]] is potentially available for interesting vehicle-related projects, or just for moving kit. She's a 1978 Series III with added 2" suspension lift, big wheels and 3.5 V8 engine. Standard towbar ball and electrics. | The Landy [[File:AndysLandy.JPG]] is potentially available for interesting vehicle-related projects, or just for moving kit. She's a 1978 Series III with added 2" suspension lift, big wheels and 3.5 V8 engine. Standard towbar ball and electrics. | ||
''''Project | ''''Project EngraveAtDifferentDepths'''' | ||
one | |||
<pre> | |||
#!/usr/bin/perl -w | |||
use strict; | |||
use CGI; | |||
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | |||
my $q = CGI->new(); | |||
print $q->header; | |||
print $q->start_html; | |||
print $q->p("this is a thing for doing threshholding"); | |||
print $q->p("<small>or possibly <i>thresholding</i>?</small>"); | |||
print $q->start_form( -enctype => "multipart/form-data" ); | |||
print $q->p("threshhold start? (0-100)"); | |||
print $q->textfield('tval'); | |||
print $q->p("threshold interval?"); | |||
print $q->textfield('tinterval'); | |||
print $q->p("file"); | |||
print $q->filefield('uploaded_file'); | |||
print $q->submit(); | |||
print $q->end_form; | |||
# do we have an upload? | |||
my $filehandle = $q->upload('uploaded_file'); | |||
if (defined $filehandle) { | |||
# do shit | |||
print $q->p("I'm doing shit"); | |||
# no, actually do shit | |||
my $filename = $q->param('uploaded_file'); | |||
my $tempfile = $q->tmpFileName($filename); | |||
my ($tval) = ($q->param('tval') =~ /^(\d+)$/); # only allow digits | |||
my ($tinterval) = ($q->param('tinterval') =~ /^(\d+)$/); # also only allow digits | |||
for (my $i = $tval; $i <= 100; $i += $tinterval) { | |||
my @ar = ("gm", "convert", "-threshold", $i."%", $tempfile, "/var/www/threshold_output/$filename".$i); | |||
system(@ar) == 0 or carp "system call failed: $?"; #safer than passing a string to system() | |||
print $q->img({src => "/threshold_output/$filename".$i}); | |||
} | |||
} | |||
print $q->end_html; | |||
</pre> | |||
two | |||
<pre> | |||
#!/usr/bin/perl -w | |||
use strict; | |||
use CGI; | |||
use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | |||
my $q = CGI->new(); | |||
print $q->header; | |||
print $q->start_html; | |||
print $q->p("this is a thing for doing threshholding"); | |||
print $q->p("<small>or possibly <i>thresholding</i>?</small>"); | |||
print $q->start_form( -enctype => "multipart/form-data" ); | |||
print $q->p("threshhold value? (0-100)"); | |||
print $q->textfield('tval'); | |||
print $q->p("file"); | |||
print $q->filefield('uploaded_file'); | |||
print $q->submit(); | |||
print $q->end_form; | |||
# do we have an upload? | |||
my $filehandle = $q->upload('uploaded_file'); | |||
if (defined $filehandle) { | |||
# do shit | |||
print $q->p("I'm doing shit"); | |||
# no, actually do shit | |||
my $filename = $q->param('uploaded_file'); | |||
my $tempfile = $q->tmpFileName($filename); | |||
my ($tval) = ($q->param('tval') =~ /^(\d+)$/); # only allow digits | |||
my @ar = ("gm", "convert", "-threshold", $tval."%", $tempfile, "/var/www/threshold_output/$filename"); | |||
system(@ar) == 0 or carp "system call failed: $?"; #safer than passing a string to system() | |||
print $q->img({src => "/threshold_output/$filename"}); | |||
} | |||
print $q->end_html; | |||
</pre> | |||