Code for image compression

Dak914's Avatar, Join Date: May 2008
Go4Expert Member
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......

Last edited by shabbir; 19Jul2008 at 06:50.. Reason: Code block
0
Dak914's Avatar, Join Date: May 2008
Go4Expert Member
If anyone can tell me how to shorten it up just a bit that would be very helpful...
0
Dak914's Avatar, Join Date: May 2008
Go4Expert Member
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
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to PERL forum
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
I didn't quite understand the objective of the program, does it combine two images into one?
0
Dak914's Avatar, Join Date: May 2008
Go4Expert Member
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