Perl Imager 图片添加倾斜文字水印

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Perl Imager 图片添加倾斜文字水印

帖子 523066680 »

result.jpg
=info
Auth: vicyang/523066680
Date: 2018-04
=cut

use Imager;
use Imager::Matrix2d;
use Data::Dumper;
use Time::Local;
use Encode;
STDOUT->autoflush(1);

my $file = "src.jpg";
my $img = Imager->new();
$img->read(file=>$file) or die "Cannot load $image_source: ", $image->errstr;

my ($width, $height) = ( $img->getwidth(), $img->getheight() );
my $fontsize = int($height/40);
my $skip = $fontsize * 5;

print "$width $height\n";

$blue = Imager::Color->new(0xB0, 0xB0, 0xB0, 0x60);
$font = Imager::Font->new(file => 'C:/windows/fonts/msyh.ttf',
color => $blue,
size => $fontsize );

my $matrix = Imager::Matrix2d->rotate( degrees => 45 );
$font->transform(matrix => $matrix);

my @str;
my $date = time_format( time() );
push @str, "Perl专栏 "x50;
push @str, "$date "x50;

for my $y ( 1 .. 25 )
{
$img->string(
font => $font,
text => decode('utf8', $str[ $y % 2 ] ),
x => 0,
y => $y * $skip,
color => $blue
);
}

$img->write( file => "result.jpg") or die $img->errstr;

sub time_format
{
my ($sec, $min, $hour, $day, $mon, $year) = localtime( shift );
$mon += 1;
$year += 1900;
return sprintf "%d-%02d-%02d %02d:%02d", $year,$mon,$day,$hour,$min;
}
原图:
src.jpg
头像
rubyish
渐入佳境
渐入佳境
帖子: 52
注册时间: 2018年04月23日 09:58
联系:

Re: Perl Imager 图片添加倾斜文字水印、平铺文字水印

帖子 rubyish »

youyisi
$_
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: Perl Imager 图片添加倾斜文字水印、平铺文字水印

帖子 523066680 »

rubyish 写了:youyisi
:jiong2
Rubyish来了
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 2 访客