Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Code for image compression (http://www.go4expert.com/forums/code-image-compression-t12235/)

Dak914 19Jul2008 00:04

Code for image compression
 
Not sure if it is really good code but i have been working on it in perl. You need Image::Magick for it to work...
here it is:

compression:

Code:

#!/usr/bin/perl
use Image::Magick;
#Ask for number of images to compress
sub first
{
        print "type the number of images to compress\n";
        print "2, 3, 4\n";
        $number=<>;
        chomp $number;
        if ($number eq 2)
        {
                &two;
        } elsif ($number eq 3) {
                &three;
        } elsif ($number eq 4) {
                &four;
        } else {
                print "your numb#!/usr/bin/perl
                        use Image::Magick;
#Ask for number of images to compress
                sub first
                {
                        print "type the number of images to compress\n";
                        print "2, 3, 4\n";
                        $number=<>;
                        chomp $number;
                        if ($number eq 2)
                        {
                                &two;
                        } elsif ($number eq 3) {
                                &three;
                        } elsif ($number eq 4) {
                                &four;
                        } else {
                                print "your number did not match any of the above numbers, try again\n\n";
                                reset (&first);
                                &first;
                        }
                }
#If desired number is two
                sub two
                {
                        print "input two images to compress\n";
                        print "1)";
                        $photo1=<>;
                        print "2)";
                        $photo2=<>;
                        chomp ($photo1, $photo2);
                        $image1=Image::Magick->new;
                        $image1->Read ("$photo1", "$photo2");
                        $image1->Write ('x2.gif');
                        undef $image1;
                        undef $photo1;
                        undef $photo2;
                        undef $number;
                        &first;
                }
#If desired number is three
                sub three
                {
                        print "input three images to compress\n";
                        print "1)";
                        $photo3=<>;
                        print "2)";
                        $photo4=<>;
                        print "3)";
                        $photo5=<>;
                        chomp ($photo3, $photo4, $photo5);
                        $image2=Image::Magick->new;
                        $image2->Read ("$photo3", "$photo4", "$photo5");
                        $image2->Write ('x3.gif');
                        undef $image2;
                        undef $photo3;
                        undef $photo4;
                        undef $photo5;
                        undef $number;
                        &first;
                }
#If desired number is four
                sub four
                {
                        print "input four images to compress\n";
                        print "1)";
                        $photo6=<>;
                        print "2)";
                        $photo7=<>;
                        print "3)";
                        $photo8=<>;
                        print "4)";
                        $photo9=<>;
                        chomp ($photo6, $photo7, $photo8, $photo9);
                        $image3=Image::Magick->new;
                        $image3->Read ("$photo6", "$photo7", "$photo8", "$photo9");
                        $image3->Write ('x4.gif');
                        undef $image3;
                        undef $photo6;
                        undef $photo7;
                        undef $photo8;
                        undef $photo9;
                        undef $number;
                        &first;
                }
                &first;er did not match any of the above numbers, try again\n\n";
                        reset (&first);
                &first;
        }
}
#If desired number is two
sub two
{
        print "input two images to compress\n";
        print "1)";
        $photo1=<>;
        print "2)";
        $photo2=<>;
        chomp ($photo1, $photo2);
        $image1=Image::Magick->new;
        $image1->Read ("$photo1", "$photo2");
        $image1->Write ('x2.gif');
        undef $image1;
        undef $photo1;
        undef $photo2;
        undef $number;
        &first;
}
#If desired number is three
sub three
{
        print "input three images to compress\n";
        print "1)";
        $photo3=<>;
        print "2)";
        $photo4=<>;
        print "3)";
        $photo5=<>;
        chomp ($photo3, $photo4, $photo5);
        $image2=Image::Magick->new;
        $image2->Read ("$photo3", "$photo4", "$photo5");
        $image2->Write ('x3.gif');
        undef $image2;
        undef $photo3;
        undef $photo4;
        undef $photo5;
        undef $number;
        &first;
}
#If desired number is four
sub four
{
        print "input four images to compress\n";
        print "1)";
        $photo6=<>;
        print "2)";
        $photo7=<>;
        print "3)";
        $photo8=<>;
        print "4)";
        $photo9=<>;
        chomp ($photo6, $photo7, $photo8, $photo9);
        $image3=Image::Magick->new;
        $image3->Read ("$photo6", "$photo7", "$photo8", "$photo9");
        $image3->Write ('x4.gif');
        undef $image3;
        undef $photo6;
        undef $photo7;
        undef $photo8;
        undef $photo9;
        undef $number;
        &first;
}
&first;

Decompression:

#!/usr/bin/perl
use Image::Magick;
print "enter gif to decompress\n";
$in=<>;
chomp $in;
$image= Image::Magick->new;
$image->Read ("$in");
$image->Write ('x.png');
undef $image;


That is all
A friend and i use it to send messages to each other...LOL Childish......

Dak914 19Jul2008 00:07

Re: Code for image compression
 
If anyone can tell me how to shorten it up just a bit that would be very helpful...

Dak914 19Jul2008 00:08

Re: Code for image compression
 
to use it just go to the directory you put the *.pl file in and type "perl *.pl"
you must type the extensions for the images
CASE SENSITIVE
~DBK

shabbir 19Jul2008 06:51

Re: Code for image compression
 
Moved to PERL forum

pradeep 19Jul2008 13:57

Re: Code for image compression
 
I didn't quite understand the objective of the program, does it combine two images into one?

Dak914 26Oct2008 06:45

Re: Code for image compression
 
Yes it does. It will create a single gif image from several other images. A gif image is seen as animations on the web. Sorry I havent been on in a while. Just been stuck doing other stuff.
Learn.
~Connor


All times are GMT +5.5. The time now is 13:23.