I have the following code to update a graphical map with ImageMagick commandline. It works fine when run directly from the website, but I am attempting to schedule it via a cronjob. It doesn't appear to be finding the images in the $m string that I build - I think due to a path issue? The full server path used in if (file_exists(...)) works, but I have tried the actual ImageMagick commend line with both full server path and local path and doesn't seem to work. Any ideas what Im doing wrong here?
$icon_on_map_fullpath = "/home/site/public_html/media/icon_on_map/";
$icon_on_map_path = "../media/icon_on_map/";
foreach($map_clusters as $mc) {
$icon_name = $mc['cluster_id'].'.png';
if (file_exists($icon_on_map_fullpath.$icon_name)) {
$m .= $icon_on_map_path.$icon_name." -geometry +".$mc['clus_x']."+".$mc['clus_y']." -composite ";
}
}
exec("convert master_map.png {$m} lastest_map.png ");
Related
I'm trying to run a test for resizing images. To do that I have an Image that I load into a File.
This works locally (in IDE and via terminal) but fails in BitBucket's pipeline.
File structure:
Code that loads the image:
String rootDir = Directory.current.path;
imagePath = rootDir + '/test/assets/test_image_gradient_black_white_3000x4000.png';
File myFile = File(filePath);
This works locally, but when run in Bitbucket's pipeline the "current path" returned "does not exist".
Error message:
00:03 +24 -4: /opt/atlassian/pipelines/agent/build/my_repository/test/image_utils_test/image_utils_test.dart: given 3000x4000 pixel file - resize with half width - verify resize and aspect ratio kept [E]
FileSystemException: Cannot open file, path = '/opt/atlassian/pipelines/agent/build/test/assets/test_image_gradient_black_white_3000x4000.png' (OS Error: No such file or directory, errno = 2)
Is it possible to load files in CI?
The path was actually wrong.
When you right click a test in android studio and select run it is run from that path.
When you run it from the terminal you have to supply the full path of your file from where you are currently standing.
Directory.current.path always returns the project root path, and since my test was in a separate module I had to add the path manually.
This should only be done if we are not already in the my_repository module, otherwise we will add the path twice and we would not be able to run the tests from the IDE instead.
This is how I calculate what to add to the string depending on where the test was executed.
String get testRootDir {
String rootDir = Directory.current.path;
String testDir =
rootDir.contains('/my_repository')
? rootDir + '/test'
: rootDir + '/my_repository/test';
return testDir;
}
...
...
final String assetPath = testRootDir + 'assets/test_image_gradient_black_white_3000x4000.png';
I am trying to read an image in Matlab using the following command as I found it in Matlab docs:
A = imread(d:/img,png)
but the problem is Matlab can not read the path and says : Error: Unexpected MATLAB operator.
I also tried using, /, //, \ and \ in the filepath, but none of them worked.
Please let me know how to get it working.
You need to put ' around the filename and the file is probably named 'img.png' (a dot not a comma)
A = imread('d:/img.png')
Also there is difference in the platforms:
path on Microsoft® Windows® platforms:
I = imread('c:/tools/goodstuff/img.png')
path on UNIX® platforms:
I = imread('/home/tools/goodstuff/img.png')
The below is working just fine
$stream = fopen($connection_string . "/var/tmp/test.test", 'r');
But
$stream = fopen($connection_string . "/var/tmp/test.#test", 'r');
Fails with an error message:
Warning: fopen(): Unable to open ssh2.sftp://Resource id #108/var/tmp/test.#test on remote host in...
test.test and test#test are working fine, only the combination of test.#test is failing.
ssh2_scp_recv() handles test.#test just fine.
CentOS release 5.8 (Final)
PHP 5.2.17
Is this a php bug? Or some special character escaping is required?
it would be interesting to know how well it works with phpseclib. eg.
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
// outputs the contents of filename.remote to the screen
echo $sftp->get('filename.remote');
// copies filename.remote to filename.local from the SFTP server
$sftp->get('filename.remote', 'filename.local');
?>
src: http://phpseclib.sourceforge.net/sftp/examples.html#get
if phpseclib didn't work you could enable logging, with phpseclib, and see what the phpseclib logs say. eg. do define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); after you include Net/SFTP.php and then do $sftp->getLog() after you try to download the file.
I try to convert odt-Files to doc-Files using OpenOffice. Installed Version is 3.1.1 and can't be changed at the moment. Perl Version is 5.18.
The Perl-module OpenOffice::UNO is used for this conversion. Unfortunately in newer Versions of OpenOffice/LibreOffice do not support Perl anymore.
The Script calls OpenOffice headless using xvfb.
Here is the code used:
`# Launch OpenOffice.org as a server
$ ooffice \
"-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"
use OpenOffice::UNO;
# connect to the OpenOffice.org server
$uno = OpenOffice::UNO->new;
$cxt = $uno->createInitialComponentContext('file:///.../path/perluno');
$sm = $cxt->getServiceManager;
$resolver = $sm->createInstanceWithContext
("com.sun.star.bridge.UnoUrlResolver", $cxt);
$rsm = $resolver->resolve
("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
# get an instance of the Desktop service
$rc = $rsm->getPropertyValue("DefaultContext");
$desktop = $rsm->createInstanceWithContext("com.sun.star.frame.Desktop", $rc);
.....`
On the last included line to create $desktop i get following Error message:
terminate called after throwing an instance of 'com::sun::star::container::NoSuchElementException'
Is there any way to fix this problem? Tried to understand the Code of the UNO-interface, especially UNO.xs but there has not been any information about the call "createInstanceWithContext".
Looking through the OpenOffice-documentation does not provide any information about this either.
It would also help just to get the complete java error message, to make sure what element is missing.
The file "perluno" has the content:
[Bootstrap]
UNO_TYPES=/usr/lib64/openoffice.org//program/types.rdb
UNO_SERVICES=/usr/lib64/openoffice.org//program/services.rdb
I have a simple requirement of screen scraping a web-page (simple URL based reports) and direct the HTML response to an output file. The URL will however redirect to an authentication (HTTPS Login) page with "form based" authentication (no javascript) and upon authentication the report I am trying to view should show up in the $response (as HTML). Interestingly, my code is working just fine in a Windows machine, however the same code below is not working in AIX machine and it looks like the click_button() function call does nothing. I have tried click(), submit(), but none is working so instead of getting the actual report all I get is the logon screen in the HTML output file. Any ideas, what can be wrong?
use WWW::Mechanize;
use strict;
my $username = "admin";
my $password = "welcome1";
my $outpath = "/home/data/output";
my $fromday = 7;
my $url = "https://www.myreports.com/tax_report.php";
my $name = "tax_report";
my $outfile = "$outpath/$name.html";
my $mech = WWW::Mechanize->new(noproxy =>'0');
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$mon++; # since it will start from 0
$mday--; # yesterdays date (to day)
$fromday = $mday - $days; #(from day)
#Create URL extension for generating report with previous date
my $dt_range = "?Y&dc_date1=$mon%2F$fromday%2F$year&dc_date2=$mon%2F$mday%2F$year";
my $url = $url . $dt_range;
$mech->get($url);
$mech->field(login => "$username");
$mech->field(passwd => "$password");
$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });
$mech->click_button(value=>"Login now");
my $response = $mech->content();
print "Generating report: $name...\n";
open (OUT, ">>$outfile")|| die "Cannot create report file $outfile";
print OUT "$response";
close OUT;
The WWW::Mechanize version in both the Machines are same i.e. 1.54 but the Win machine perl version is 5.10.1 whereas the AIX machine's Perl version is 5.8.8.
Other Alternatives Used -
my $inputobject=$mech->current_form()->find_input( undef,'submit' );
print $inputobject->value . "\n";
$mech->click_button(input => $inputobject);
print $mech->status() . "\n";
The $inputobject shows the correct button element as in the HTML source and the second print returns a status of 200 which apparently stands for OK. But its still not working in the AIX machine.
UPDATE- It seems that the site I am trying to connect to has an un-trusted SSL certificate. I tried the program on three different machines Windows PC, Mac and AIX. On the Windows Machine the program works and I was able to login to the website through the browsers (Chrome, Firefox,IE). However in Mac, the login just won't work (through the browsers) and it shows an un-trusted certificate error (or warning!) this probably means the proxy settings are not set up, the Perl program won't work either. And lastly the AIX where the Perl is not working as well. Not sure how to bypass this un-trusted SSL certificate issue here. Any help will be appreciated.
UPDATE2: Included below lines of code in the script to see logging details and found that I was being re-directed (HTTP 302) since my IP was filtered by the server Firewall. Once the AIX ip was added to the server's firewall exception the script worked perfectly. The two lines below were the life saver-
$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });
Can you use the following line before my $mech = WWW::Mechanize->new(noproxy =>'0'); of your perl code and try again ?
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;