Need an image resize script made in CGI Pearl

Posted on 2008-11-05
Medium Priority
Last Modified: 2013-12-25

Do anyone have a simple image resize script made in CGI pearl that can resize images without loosing its quality?
Question by:Gurbirs
  • 2
LVL 39

Accepted Solution

Adam314 earned 1500 total points
ID: 22886302
When you resize an image smaller, you are removing pixels, so it will lose quality.  If you make it bigger, you are adding pixels, and the colors for those pixels has to be made up somehow.  This sometimes causes pixelation, but some resize algorithms are better than others.

Anyway, you can use the Image::Resize.  
use strict;
use CGI ':standard';
use Image::Resize;
my $image = Image::Resize->new('large.jpg');
my $gd = $image->resize(250, 250);
open(my $out, ">Small.jpg") or die "Couldn't open/write: $!\n";
print $out $gd->jpeg();
print header();
print "<html><body>Success!</body></html>\n";

Open in new window


Expert Comment

ID: 24564001
so this doesn't use GD or any other library?

This is now in Perl? and this works in gif and png?
LVL 39

Expert Comment

ID: 24604452
bs98909 - This really should be a new question.  But a quick answer here: It uses the GD library.  Documentation is available here:
If you have follow-up questions, please start a new question.

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question