magick, Hello. Thanks for the quick response. I checked as you requested, and do not really have a problem. All this time I tested.
The problem is still relevant for me. Here's the code of the script which I use, maybe you can help ..
I tried different ways to use "Image::Magick", as he has in the script => is a memory leak.
Code: Select all
#!/usr/bin/perl -w
use diagnostics;
use warnings;
use strict;
use DBI;
use LWP::Simple;
use Image::Magick;
sub ImgReplace {
my ($row, $water, $waterS) = @_;
my $name = $row->{name};
my $status = $row->{retry_count};
if ($row->{url} =~ m/udp/i) { # - So you need..
print "Do nothing - ".$name."\n";
} else {
#
my $image_url = 'https://localhost/'.$name.'/preview.jpg';
my $image_temp = '/home/firsim/temp/'.$name.'.jpg';
my $rc = getstore($image_url, $image_temp);
if (is_error($rc)) {
print "getstore of <$image_url> failed with $rc\n";
}
# - Saving an image from the web server to the local. So you need..
#
my $image_patch = '/var/www/temp/preview/'.$name.'.jpg';
my $image_patchS = '/var/www/temp/preview/nosignal/'.$name.'.jpg';
my $image_patchT = '/var/www/temp/preview/'.$name.'.jpg.tmp';
my $image_patchST = '/var/www/temp/preview/nosignal/'.$name.'.jpg.tmp';
# - Template links.
if(-e "$image_temp") { # - Check for file.
#
my $image = Image::Magick->new;
$image->Read($image_temp);
$image->AdaptiveResize(geometry=>'900x');
$image->Crop(geometry=>'895x500+0+0', gravity=>'center',);
$image->Composite(image=>$water, compose=>'Atop', y=>-220, x=>290);
if ($status ne 0) {
$image->Composite(image=>$waterS, compose=>'Atop');
$image->Write(filename => $image_patchT, quality=>'85');
$image->Write(filename => $image_patchST, quality=>'85');
} else {
$image->Write(filename => $image_patchT, quality=>'85');
$image->Composite(image=>$waterS, compose=>'Atop');
$image->Write(filename => $image_patchST, quality=>'85');
}
# - Some manipulation of the image and save.
}
#
rename $image_patchT, $image_patch;
rename $image_patchST, $image_patchS;
# - Save.
}
}
sub StartArray {
my $watermark = '/home/firsim/perl/ImgReplace/watermark.png'; # - The path to the watermark 1
my $watermarkS = '/home/firsim/perl/ImgReplace/nosignal.png'; # - The path to the watermark 2
my $water = Image::Magick->new;
my $waterS = Image::Magick->new;
$water->Read($watermark);
$waterS->Read($watermarkS);
my $db = DBI->connect("DBI:mysql:$database:$hostname", $user, $password); # - Array in DB.
$db->do("SET NAMES 'utf8'");
###
my $array = $db->prepare("SELECT * FROM `streams` ORDER by `name` ASC;") or print $DBI::errstr;
$array->execute() or print $DBI::errstr;
while(my $row = $array->fetchrow_hashref){
ImgReplace($row, $water, $waterS); # - Then we pass the incoming data into a function creating previews.
}
$db->disconnect;
}
# Run script
while (1) {
StartArray;
sleep 60;
}