I have an irssi bot that saves me the images in mysql database but before saving them I would like to make a resize maintaining the quality, the images have all different resolutions.
the code to which I must add the resize is this
sub saveJpg {
my ($text, $server, $channel, $nick) = @_;
my $time = time();
my ($pre, $url, $jpgname, $checksum) = split(" ", $text);
$pre = trim($pre);
$url = trim($url);
$jpgname = trim($jpgname);
if (length($jpgname) > $limits{'jpgnameLength'}) {
my $message = "[".$red."ERROR".$reset."] ".$darkgrey."savejpg()--[jpg file name too long]--[!addjpg $pre $url $jpgname ]--[$nick]--[$channel]";
announceError($server, $message);
printDebug("savejpg()--[Filename too long]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
return 0;
}
my $jpg2 = stripBadCharsFile($jpgname);
my $url2 = stripBadCharsUrl($url);
# escape ( and ) chars
$jpg2 =~ s/\(/\\\(/g;
$jpg2 =~ s/\)/\\\)/g;
$url2 =~ s/\(/\\\(/g;
$url2 =~ s/\)/\\\)/g;
my $hash = md5_hex($pre);
my $botId = checkBot($nick, "jpg");
if (!$botId) {
printDebug("savejpg()--[Bot $nick does not have jpg saving rights]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
return 0;
}
if (checkIfPreExists($pre) != 1) {
my $message = "[".$red."ERROR".$reset."] ".$darkgrey."savejpg()--[No such pre in db]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]";
announceError($server, $message);
printDebug("savejpg()--[No such pre in db]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
return 0;
}
if ($pre) {
my $sql = "SELECT [login to view URL], [login to view URL], [login to view URL] FROM jpgs j LEFT JOIN releases AS r ON [login to view URL] = [login to view URL] WHERE [login to view URL] = ? and [login to view URL] = ? LIMIT 1";
my @params = ($pre, $jpgname);
if (runSqlSingle($sql, @params)) {
printDebug("saveJpg()--[Jpgs already exists]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
return 0;
}
}
printDebug("savejpg()--[!addjpg $pre $url $jpgname]--[$nick]--[$channel]--START--");
my $releaseId = getReleaseId($pre);
my $channelId = getChannelId($channel);
my $command = "wget -q -T 1 -t 1 --no-check-certificate --content-disposition -O $jpg2 $url2";
system($command);
rename("$jpgname", "$hash");
my $filesize = -s "$hash";
if ($filesize < 10000 || $filesize > 4240000 ) {
unlink("$hash");
printDebug("savejpg()--[Invalid filesize]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
return 0;
}
open(FILE, "$hash") or die $!;
my @data = <FILE>;
close FILE;
my $jpgdata = join('',@data);
$jpgdata = encode_base64($jpgdata);
my $sql = "INSERT INTO jpgs(releaseid, hash, jpg, jpgname, time, \
channelid, botid) VALUES (?, ?, ?, ?, ?, ?, ?)";
my @params = ($releaseId, $hash, $jpgdata, $jpgname, $time, $channelId, $botId);
if (!runSqlSave($sql, @params)) {
my $message = "[".$red."ERROR".$reset."] ".$darkgrey."savejpg()--[Unable to save jpg into db]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]";
announceError($server, $message);
printDebug("savejpg()--[Unable to save jpg into db]--[!addjpg $pre $url $jpgname $checksum]--[$nick]--[$channel]");
unlink("$hash");
return 0;
}
Hello
More 20 years programming experience.
I need more details to set real price and time.
Regards.
---------------------------------------------------------------------------------------------------------------------------------------------------