Menu
  • HOME
  • TAGS

How do I “read” from an existing image object instead of a file path with PerlMagick?

Tag: perl,imagemagick,montage,perlmagick

The following code generates a 300x100 image using a 100x100 tile as a source image:

for (my $i = 0; $i < 3; $i++) {
    $image->Read("filepath/100x100.png");
}

$result = $image->Montage(geometry=>'100x100',tile=>'3x1');

How do I reach the same result while only reading once from disk?

Best How To :

It's not obvious from the docs, but you can add clones to the image sequence like this:

$image->Read("filepath/100x100.png");
$image->[1] = $image->[0]->Clone();
$image->[2] = $image->[0]->Clone();

$result = $image->Montage(geometry=>'100x100',tile=>'3x1');

Get ISO DateTime with only core modules in Perl?

perl

This is simple with the POSIX function strftime: use POSIX qw( strftime ); print strftime "%Y-%m-%d %H:%M:%S", localtime; POSIX has been core since 5.0....

Windows/Linux child process STDIN differences

linux,windows,perl,process,stdin

This isn't a Windows verus Linux thing. You simply picked two awful examples. type con reads from the console, not from STDIN. This can be seen using type con <nul. cat is extremely unusual. Buffering, on either system, is completely up to the individual application, but almost all applications work...

What happens to a non-matching regex in a Perl subroutine call?

perl

When the match operator =~ is used in list context it returns a list of matches. When there are no matches this list is empty (also called the empty list), and the empty list is passed to your sub routine which in turn causes @_ to be empty. If you...

Plain text emails displayed as attachment on some email clients

perl,email,attachment,mime,plaintext

I think this is the closes thing you're going to get to an answer The documentation for MIME::Lite says this MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue...

Difficulties initializing an array in Perl

arrays,perl,hash

$dec_res->{repositories} is clearly an array It isn't. It is an array reference. but @repos is not? It is an array. You are creating a list that is one item long, and that item is the array reference. You then assign the list to the array, so the array holds...

I can't convert with ImageMagick

php,centos,imagemagick

First of all, two observations: The message you see is not from ImageMagick, it is from Ghostscript. The message is not an error message, but merely a warning. So it may well be that your conversion did work and you'll have the desired output in $image_path. Did you check? Then,...

Perl : Display perl variable awk sed echo

perl

You can do that using a Perl regex pattern my $calculate; ($calculate = $1) =~ tr~,~/~ if $value =~ /SP=[^:]*:([^;]*)/; ...

Capture tee's argument inside piped Perl execution

perl,unix

The short answer is - you can't. tee is a separate process with it's own arguments. There is no way to access these arguments from that process. (well, I suppose you could run ps or something). The point of tee is to take STDOUT write some of it to a...

Reading from DATA file handle

performance,perl

I did some benchmarking against three methods. I used an external file for reading (instead of __DATA__). The file consisted of 3 million lines of the exact data you were using. The methods are slurping the file, reading the file line-by line, and using Storable as Sobrique mentioned above. Each...

Creating a sequence of unique random digits

arrays,perl,foreach,unique

To generate a list of four unique non-zero decimal digits, use shuffle from List::Util and pick the first four Like this use strict; use warnings; use 5.010; use List::Util 'shuffle'; my @unique = (shuffle 1 .. 9)[0..3]; say "@unique"; output 8 5 1 4 There's no need to seed the...

How to match and remove the content preceding it from a file in unix [closed]

mysql,perl,sed,solaris

with GNU sed sed -n '1,/-- Final view structure for view `view_oss_user`/p' this will print lines from 1 till pattern found, others will not be printed or if you want to exclude pattern line then sed -n '1,/-- Final view structure for view `view_oss_user`/p' | sed '$d' ...

Check for decimal point and add it at the end if its not there using awk/perl

regex,perl,shell,awk

In awk Just sub for those fields awk -F, -vOFS="," '{sub(/^[^\.]+$/,"&.",$6);sub(/^[^\.]+$/,"&.",$11)}1' file or sed sed 's/^\(\([^,]*,\)\{5\}[^.,]\+\),/\1./;s/^\(\([^,]*,\)\{10\}[^.,]\+\),/\1./' file ...

How to copy matches from an extremely large file if it contains no newlines?

python,linux,bash,perl,grep

#!/usr/bin/perl use strict; use warnings; use constant BLOCK_SIZE => 64*1024; my $buf = ""; my $searching = 1; while (1) { my $rv = read(\*STDIN, $buf, BLOCK_SIZE, length($buf)); die($!) if !defined($rv); last if !$rv while (1) { if ($searching) { my $len = $buf =~ m{\[(?:a|\z)} ? $-[0] : length($buf);...

How to pass a hash as optional argument to -M in command line

perl,hash,package,command-line-interface

Looking at perlrun use: perl -Mfeature=say "-Mconstant {c1 => 'foo', c2 => 'bar'}" -e"say c1,c2" ...

Imagick Interprets external image as HTML

php,imagemagick,imagick

I strongly recommend not using Imagick for downloading images from other servers. Either use CURL or some other library that gives you adequate control over the download (including being able to see redirects, incorrect content types, etc), and then process the image with Imagick once it is downloaded correctly. Source...

How to lighten an image using ImageMagick like when using compare?

imagemagick

I assume you would like to lighten 2nd image so you get 3rd but without text. So from command line this should give same results: convert porsche.png -fill white -colorize 80% porshe_light.png ...

Create unicode character with pack

perl,unicode

Why do I get ff and not c3bf when using pack ? This is because pack creates a character string, not a byte string. > perl -MDevel::Peek -e 'Dump(pack("U", 0xff));' SV = PV(0x13a6d18) at 0x13d2ce8 REFCNT = 1 FLAGS = (PADTMP,POK,READONLY,pPOK,UTF8) PV = 0xa6d298 "\303\277"\0 [UTF8 "\x{ff}"] CUR =...

How to extract some text from an HTML doc using Web::Query

perl

The dot selector denotes class selections, which is not what you intend for the second div and h3. For these you want descendant. The correct syntax is; my $subject = $parts->find( 'div.subject > div > h3' )->text; # Which outputs # subjectfinal $VAR1 = '@if version_after macro is illogical'; For...

Perl would I use fc over uc?

perl

fc is used for case-insensitive comparisons. uc($a) cmp uc($b) # XXX lc($a) cmp lc($b) # XXX fc($a) cmp fc($b) # ok An example where this makes a difference: lc uc fc -- -- -- -- ss ss SS ss SS ss SS ss ß ß SS ss ẞ ß ẞ...

Deleting upto a line

bash,perl,shell,sed,scripting

Try this: grep -oE '[0-9.-]+$' file or awk '{print $NF}' file ...

Reducing code verbosity and efficiency

perl

There is a famous quote: "Premature optimisation is the root of all evil" - Donald Knuth It is almost invariably the case that making code more concise really doesn't make much difference to the efficiency, and can cause significant penalties to readability and maintainability. Algorithm is important, code layout ......

Perl: Multiply loops, 1 hash and regex

arrays,regex,perl,hash,perl-data-structures

you need to append the file when you output meaning use ">>" instead of ">" which will overwrite the file. system("chage -l $_ >> $pwdsett_dump") as you are running it in loop you are overwriting each time the loop executes. Use: foreach (@Usernames) { system("chage -l $_ >> $pwdsett_dump") }...

Perl & Regex within Windows CMD Line

regex,windows,perl

If I understand correctly, you want to pull out all of the matches from an entire file, and write those results to a separate file. This will work if the below results are what you're after. I don't have a Windows box to test on, but this should work (you...

How to store ImageMagick output into Bash variable (and then use it)?

bash,imagemagick,imagemagick-convert

Bash can not store blobs of data that may contain NULL terminating characters. But you can convert the data to base64, and use ImageMagick's fd: protocol. # Store base64-ed image in `data' data=$(convert logo: -shave 1x1 gif:- | base64) # Pass ASCII data through decoding, and pipe to stdin file...

Why does my value change when I am not resetting it?

perl,reference

Try using @favcols = map { [@$_] } @actors; @favanim = map { [@$_] } @actors; Deep copy vs shallow copy....

Why this exclusion not working for long sentences?

text-processing,perl

You're using the wrong syntax: [] is used to match a character class, while here you're trying to match a number of occurences of ., which can be done using {}: perl -ne 'print unless /.{240,}/' input.txt > output.txt Also, as suggested by salva in the comments, the pattern can...

Looping variables

perl,scripting

As per my comment, most of the functionality of your program is provided by the Math::Vector::Real module that you're already using It looks like you want the angle in degrees between successive pairs of 3D vectors in your file. This code creates vectors from each line in the file until...

Why Filter::Indent::HereDoc complain when blank line in middle of HereDoc

perl,heredoc

The documentation says: If there is no terminator string (so the here document stops at the first blank line), then enough whitespace will be stripped out so that the leftmost character of the document will be flush with the left margin, e.g. print <<; Hello, World! # This will print:...

Find numbers in a file and change their value with perl

regex,perl

You can just match the numbers that are less than one.. and replace with 1: perl -pe 's/\b0\.\d+/1/g' file See DEMO...

calling cgi script from other cgi script

perl,cgi

A CGI program normally expects to fetch the parameter values from the environment variable QUERY_STRING. Passing parameter values on the command line is a debugging facility, and works only when the program is run from the command prompt You could try something like this my $result = do { local...

Command line arguments in Perl

perl

$! and $_ are global variables. For more information you can read here $_ The default input and pattern-searching space $! If used in a numeric context, yields the current value of the errno variable, identifying the last system call error. If used in a string context, yields the corresponding...

Counting occurrences of a word in a string in Perl

regex,perl

I get the correct number - 6 - for the first string However your method is wrong, because if you count the number of pieces you get by splitting on the regex pattern it will give you different values depending on whether the word appears at the beginning of the...

Perl - an array content

arrays,perl

You can use grep to go through the array one at a time and see if any match: if ( grep $file ~= /\Q.$_\z/, @array ) { Or join the array elements into a single regex: my @array = qw(avi mp4 mov); my $selected_extensions = qr/^\.(?:@{[ join '|', map quotemeta,...

how to print all the lines of a text file from hash - perl

perl

You have while (my $line =<$fh>) which reads a single record via $fh. The default input record separator in Perl is "\n" meaning you are reading the file line-by-line. By definition, a single line has a single line-terminator. chomp ($line); then removes this single "\n" from the string in $line....

Perl XML-RPC output format/schema

php,xml,perl,rpc,xml-rpc

Your own XML is quite different. The contents of the parameter are correct <value> <struct> <member> <name>utilisateur</name> <value> <string>user</string> </value> </member> <member> <name>motdePasse</name> <value> <string>pass</string> </value> </member> </struct> </value> but the version sent by the PHP code has this wrapped in a named structure, like this <value> <struct> <member>...

-M Script start time minus file modification time, in days

perl,perldoc

I think this explains what you are seeing perl -E 'say "START TIME",$^T; qx(touch $_), sleep(5), say -M for "/tmp/file"; say "STAT ON FILE", (stat(_))[9]' output when I ran it START TIME1434460114 0 STAT ON FILE1434460114 1) script starts $^T is set to 1434460114 2) almost immediately the file "/tmp/file"...

unable to understand qr interpolation

regex,perl

The chapter of the Perl documentation that deals with this is called perlre. In the extended pattern matching section it explains this. Starting in Perl 5.14, a "^" (caret or circumflex accent) immediately after the "?" is a shorthand equivalent to d-imsx . Flags (except "d" ) may follow the...

Can't locate module(s) using Mojo::DOM

perl,dom,mojolicious,mojo

It's very difficult to debug a single long chained statement like that, and you're much better off splitting it into individual steps Passing a parameter to the dom method is the same as calling find with that parameter on the DOM object. find returns a Mojo::Collection, which makes sense as...

How can I replace the white rectangle within an image using ImageMagick?

php,image-processing,imagemagick

I think you can locate the shape pretty accurately with a simple threshold, like this: convert image.jpg -threshold 90% result.jpg and you can then do a Canny edge detection like this: convert image.jpg -threshold 90% -canny 0x1+10%+30% result.jpg The next things I would be looking at are, using the -trim...

How to tell Perl to always run with use v5.010?

perl

You could set the default perl command-line options using the PERL5OPT environment variable PERL5OPT=-M5.010 or, more safely PERL5OPT=-Mfeature=say ...

Opening multiple files in perl array

arrays,perl

You just need to enclose the code that handles a single file in a loop that iterates over all of the log files You should also reconsider the amount of comments that you use. It is far better to write your code and choose identifiers so that the behaviour is...

C++ - back to start of loop without checking the condition

c++,perl,loops,redo

There is no redo keyword for going back to the start of a loop, but there's no reason you couldn't do it with goto. (Oh I feel so dirty recommending goto...) int tries = 0; for(int i=0; i<10; ++i) { loop_start: bool ok = ((i+tries)%3==0); if(ok) { ++tries; goto loop_start;...

Print all non-matching items in Perl

regex,perl,if-statement,matching

How about using something like Text::Diff instead of building your own? See the comments for the explanation about how you didn't use a capture group to set $1....

Perl: Using Text::CSV to print AoH

arrays,perl,csv

Pretty fundamentally - CSV is an array based data structure - it's a vaguely enhanced version of join. But the thing you need for this job is print_hr from Text::CSV. First you need to set your header order: $csv->column_names (@names); # Set column names for getline_hr () Then you can...

Version-dependent fallback code

perl

Many recent features are not forward-compatible. As you've seen, you'll get compile-time errors using a feature that is too new for the version of perl you are running. Using block-eval won't help, because the contents of the block need to be valid for the current perl interpreter. You are on...

Perl Debugging Using Flags

perl,debugging,script-debugging

In perl, compile time is also run time. So there's really not a great deal of advantage in using #define type statements. My usual trick is: my $debug = 0; $debug += scalar grep ( "-d", @ARGV ); (GetOpt is probably honestly a better plan though) And then use: print...

problems copying shared hash in perl threads

multithreading,perl

Two threads are iterating over the same hash at the same time, so they are both changing its iterator. You need to make sure that no more than one thread uses the hash's iterator at a time. I'd remove all those :shared and use Thread::Queue::Any....

Regex in Perl Uninitialized $1

regex,perl

$1 is the value captured by the first capture (()), but you have no captures in your pattern. Fix: /(?<=File `..\/)(.*)(?=')/ Simplified: m{File `../(.*)'} More robust: m{File `../([^']*)'} ...

Taking multiple header (rows matching condition) and convert into a column

bash,perl,command-line,awk,sed

In awk awk -F, 'NF==1{a=$0;next}{print a","$0}' file Checks if the number of fields is 1, if it is it sets a variable to that and skips the next block. For each line that doesn't have 1 field, it prints the saved variable and the line And in sed sed -n...

What does this horribly ugly (yet somehow secretly beautiful) Perl code do?

perl,formatting,deobfuscation

Passing the code to Google returns this page that explains qrpff is a Perl script created by Keith Winstein and Marc Horowitz of the MIT SIPB. It performs DeCSS in six or seven lines. The name itself is an encoding of "decss" in rot-13. See also qrpff explained....