Skip Menu |

This queue is for tickets about the ODF-lpOD CPAN distribution.

Report information
The Basics
Id: 74974
Status: resolved
Priority: 0/
Queue: ODF-lpOD

People
Owner: Nobody in particular
Requestors: DJIBEL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 1.118
Fixed in: 1.119



Subject: Add an image
Dear, Since I have updated ODF::lpOD from 1.117 to 1.118, I am not able to insert an image in a new ODT document. I have the same error message : read_file 'Pictures/my-image.png' - sysopen: No such file or directory at C:/Perl/site/lib/ODF/lpOD/Common.pm line 731 I have tried these codes : $doc->add_file( '/home/djibel/my-image.png', path => 'Pictures/my-image.png', type => 'image/png', ); and $doc->add_file( '/home/djibel/my-image.png', type => 'image/png', ); I have Perl 5.14 on XP Win32. Best regards, Djibel
Unfortunately I can't reproduce the issue in my environment (Linux x86_64 with Perl 5.12.4), where add_file() works.

Did you have run the same program without error using a previous version of ODF::lpOD ?

First could you please check if the lpod_test utility works for you ?
It's provided with the ODF::lpOD distro, you have to launch it with an arbitrary file name as argument. This command should create a new ODT document containing an image. You can check this document through a text processor: if everything is OK a logo should be visible in the page header. This utility uses the add_image_file() method that in turn uses add_file().

If something is wrong with lpod_test, then it's an issue with Perl 5.14 and/or Win32.

Thank for your report

Le 2012-02-13 16:56:36, DJIBEL wrote :
Show quoted text
> Dear,
>
> Since I have updated ODF::lpOD from 1.117 to 1.118, I am not able to
> insert an image in a new ODT document. I have the same error message :
>
> read_file 'Pictures/my-image.png' - sysopen: No such file or directory
> at C:/Perl/site/lib/ODF/lpOD/Common.pm line 731
>
> I have tried these codes :
>
> $doc->add_file(
> '/home/djibel/my-image.png',
> path => 'Pictures/my-image.png',
> type => 'image/png',
> );
>
> and
>
> $doc->add_file(
> '/home/djibel/my-image.png',
> type => 'image/png',
> );
>
> I have Perl 5.14 on XP Win32.
>
> Best regards,
>
> Djibel

Show quoted text
> Did you have run the same program without error using a previous > version of > ODF::lpOD ?
Yes, if I used ODF::lpOD 1.117 the program work without errors. Show quoted text
> First could you please check if the lpod_test utility works for you ? > It's provided with the ODF::lpOD distro, you have to launch it with an > arbitrary file name as argument. This command should create a new ODT > document > containing an image. You can check this document through a text > processor: if > everything is OK a logo should be visible in the page header. This > utility uses > the add_image_file() method that in turn uses add_file().
I have checked lpod_test on XP Win32 with Perl 5.14 and ODF::lpOD 1.118. It works ! Djibel
Le 2012-02-14 05:53:56, DJIBEL wrote:
[...]
Show quoted text
>
> Yes, if I used ODF::lpOD 1.117 the program work without errors.
>

OK, it's probably a Win32 filesystem-specific regression introduced by ODF::lpOD 1.118.
In the last version, add_file() has been improved in order to be able to get files through remote URLs; this improvement may have introduced some platform-dependent issues.

[...]
Show quoted text
> I have checked lpod_test on XP Win32 with Perl 5.14 and ODF::lpOD 1.118.
> It works !

So, we know that add_file() works on Win32 in some circumstances and fails in other ones.

The most strange thing is the sysopen error message with a 'Pictures/xxx' file path; this path in the internal path in the destination ODF file (that is a zip archive), it's not the path to the source image file. Apparently add_file(), in your environment, ignores your '/home/xxx' path and attempts to load a source file using the zip-related destination path; of course, it fails because there is no 'Pictures/xxx' path in the file sytem. I've to investigate this strange behavior.

Now could you insert some trace messages before and after the add_file() instruction AND before and after the line containing the save() instruction
(knowing that add_file() produce some effects immediately but that the physical file access is really done when the document is saved)



#!/usr/bin/perl use Carp; use strict; use warnings; use 5.010_000; use ODF::lpOD; my $doc = odf_document->create('text'); my $contexte = $doc->get_body; say "Before add_file"; $doc->add_file( 'oasis_odf_logo.png', path => 'Pictures/oasis_odf_logo.png', type => 'image/png', ); say "After add_file"; say "Before Frame"; my $frame = odf_frame->create( image => 'Pictures/oasis_odf_logo.png', description => 'description', title => 'title', ); say "after Frame"; my $paragraphe_vide = $contexte->append_element( odf_create_paragraph() )->append_element($frame); say "Before Save"; $doc->save(target => "AddFile.odt"); say "After Save"; exit; __END__ Result ( XP, Perl 5.14 ) : Before add_file After add_file Before Frame read_file 'Pictures/oasis_odf_logo.png' - sysopen: No such file or directory at C:/Perl/site/lib/ODF/lpOD/Common.pm line 731
I suspect something that is not directly related to add_file(), but could be an issue in ODF::lpOD::Frame.

When your frame is created, the 'size' option is not provided. In such a case, lpOD attempts to set a default size according to the original size of the image file. So it tries to get a physical access to the image resource, whose path is provided through the 'image' parameter. The error occurs during this particular operation.

I suggest you a simple workaround: create the frame with an explicit 'size' parameter, so the create() method will not attempt to analyze the image file.

If you don't know the right size, use add_image_file() instead of add_file(), knowing that (in array context), add_image_file() will return the internal path and the size; the size is returned is a format that is convenient for the 'size' option in odf_frame->create().

Note that you can safely omit the 'path' and 'type' options in add_image_file(); this method can calculate the right values automatically.

Please let me know the result. If this workaround works I'll either document or fix this issue in the next release.


Le 2012-02-14 06:42:04, DJIBEL a écrit :
Show quoted text
> #!/usr/bin/perl
> use Carp;
> use strict;
> use warnings;
> use 5.010_000;
> use ODF::lpOD;
>
> my $doc = odf_document->create('text');
> my $contexte = $doc->get_body;
>
> say "Before add_file";
> $doc->add_file(
> 'oasis_odf_logo.png',
> path => 'Pictures/oasis_odf_logo.png',
> type => 'image/png',
> );
> say "After add_file";
>
> say "Before Frame";
> my $frame = odf_frame->create(
> image => 'Pictures/oasis_odf_logo.png',
> description => 'description',
> title => 'title',
> );
> say "after Frame";
>
> my $paragraphe_vide = $contexte->append_element( odf_create_paragraph()
> )->append_element($frame);
>
>
> say "Before Save";
> $doc->save(target => "AddFile.odt");
> say "After Save";
>
> exit;
>
> __END__
>
>
>
> Result ( XP, Perl 5.14 ) :
>
> Before add_file
> After add_file
> Before Frame
> read_file 'Pictures/oasis_odf_logo.png' - sysopen: No such file or
> directory at C:/Perl/site/lib/ODF/lpOD/Common.pm line 731
>


Hum !! The problem was the size of Frame, but the real problem was image_size method. In fact, I use this code : my $size_image_pt = image_size($image); my $frame = odf_frame->create( image => 'Pictures/image.png', size => $size_image_pt, description => 'description', title => 'title', ); Since ODF::lpOD 1.118, for some images, $size_image_pt is undef. If I use my ( $path, $size ) = $doc->add_image_file($src); $size is undef too. Then, I have the sysopen error message. If I use ODF::lpOD 1.117, no problem.
OK, the issue comes from a change in the file path interpretation in the last version of image_size().

This function has been improved in order to be able to calculate the size of remote images (i.e. http://path...) as well as local ones. Due to this change, the path is apparently sometimes misinterpreted in a Windows file system.
I take the bug and I will fix it fir the next release.

In the mean time, I suggest you to use 1.117. But, just in order to help me to lock the issue, could you execute a last test with a remote image (anywhere in the web), such as in the code below, and tell me if it works on Win32:

($path, $size) = add_image_file('http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png')


On 2012-02-14 08:05:52, DJIBELwrote :
Show quoted text
> Hum !!
> The problem was the size of Frame, but the real problem was image_size
> method.
>
> In fact, I use this code :
> my $size_image_pt = image_size($image);
> my $frame = odf_frame->create(
> image => 'Pictures/image.png',
> size => $size_image_pt,
> description => 'description',
> title => 'title',
> );
>
> Since ODF::lpOD 1.118, for some images, $size_image_pt is undef. If I use
>
> my ( $path, $size ) = $doc->add_image_file($src);
>
> $size is undef too.
>
> Then, I have the sysopen error message.
>
> If I use ODF::lpOD 1.117, no problem.
>
>


Perl 5.14 - Win32 XP #!/usr/bin/perl use Carp; use strict; use warnings; use 5.010_000; use ODF::lpOD; use Cwd; my $doc = odf_document->create('text'); my $contexte = $doc->get_body; my $src = 'http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png'; my $image = $doc->add_file( $src, path => 'Pictures/Wikipedia-logo.png', type => 'image/png', ); my $size_image_pt = image_size($src); if ( not defined $size_image_pt ) { say "image_size return undef, test add_image_file method"; my ( $path, $image_size ) = $doc->add_image_file($src); if ( not defined $path ) { say "\t\$path not defined"; } elsif ( not defined $image_size ) { say "\t\$image_size not defined"; } else { say "NNNNNNNNNNNN \$path : $path\n \$image_size : $image_size"; $size_image_pt = $image_size; } } say "\$image : $image"; say "\$src : $src"; my $frame = odf_frame->create( image => $image, size => $size_image_pt, description => 'description', title => 'title', ); my $paragraphe_vide = $contexte->append_element( odf_create_paragraph() )->append_element($frame); $doc->save(target => "AddFile.odt"); exit; __END__ Result : ============================= image_size return undef, test add_image_file method $image_size not defined $image : Pictures/Wikipedia-logo.png $src : http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png read_file 'Pictures/Wikipedia-logo.png' - sysopen: No such file or directory at C:/Perl/site/lib/ODF/lpOD/Common.pm line 731 ============================= Le Mar 14 Fév 2012 15:19:21, JMGDOC a écrit : Show quoted text
> OK, the issue comes from a change in the file path interpretation in > the last > version of image_size(). > > This function has been improved in order to be able to calculate the > size of > remote images (i.e. http://path...) as well as local ones. Due to this > change, > the path is apparently sometimes misinterpreted in a Windows file > system. > I take the bug and I will fix it fir the next release. > > In the mean time, I suggest you to use 1.117. But, just in order to > help me to > lock the issue, could you execute a last test with a remote image > (anywhere in > the web), such as in the code below, and tell me if it works on Win32: > > ($path, $size) = >
add_image_file('http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia- Show quoted text
> logo.png') > > > On 2012-02-14 08:05:52, DJIBELwrote :
> > Hum !! > > The problem was the size of Frame, but the real problem was
> image_size
> > method. > > > > In fact, I use this code : > > my $size_image_pt = image_size($image); > > my $frame = odf_frame->create( > > image => 'Pictures/image.png', > > size => $size_image_pt, > > description => 'description', > > title => 'title', > > ); > > > > Since ODF::lpOD 1.118, for some images, $size_image_pt is undef. If
> I use
> > > > my ( $path, $size ) = $doc->add_image_file($src); > > > > $size is undef too. > > > > Then, I have the sysopen error message. > > > > If I use ODF::lpOD 1.117, no problem. > > > >
With this URL, previous program work : http://st.pimg.net/tucs/img/cpan_banner.png LWP doesn't download http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png (403 forbidden).
I have tried this program : #!/usr/bin/perl use Carp; use strict; use warnings; use 5.010_000; use ODF::lpOD; my $doc = odf_document->create('text'); my $contexte = $doc->get_body; my $src = 'C:\image.jpg'; my $image = $doc->add_file( $src ); use Image::Size; my ($w, $h) = Image::Size::imgsize($src); $w .= 'pt'; $h .= 'pt'; my $size_image_pt = [$w, $h]; my $frame = odf_frame->create( image => $image, size => $size_image_pt, description => 'description', title => 'title', ); my $paragraphe_vide = $contexte->append_element( odf_create_paragraph() )->append_element($frame); $doc->save(target => "AddFile.odt"); exit; __END__ The ODT file is created, but Image is empty. I have unzip the ODT file Pictures directory contains empty image file (image.jpg : 0Ko). Best Regards
OK, the bug looks qualified:

1) image_size() and add_file() work in a Unix file system with a Unix local file path or a URL);

2) image_size() and add_file() work in a Windows environment with URL but fail with a local file path.


A possible workaround (to be checked) could be a systematic use of URLs for local liles, for example:

$doc->add_image_file('file://c:/path/file.png')
or
$doc->add_image_file('file://c:\path\file.png')

instead of

$doc->add_image_file('C:\path\file.png');


As soon as the given source path is recognized as a URL, lpOD internally uses LWP to get the resource; so, with a 'file://'  prefix systematically added to any local file path it's possible (hopefully) to avoid the issu with Windows local files.


Le 2012-02-15 06:04:00, DJIBEL a écrit :
Show quoted text
> I have tried this program :
> #!/usr/bin/perl
> use Carp;
> use strict;
> use warnings;
> use 5.010_000;
> use ODF::lpOD;
>
> my $doc = odf_document->create('text');
> my $contexte = $doc->get_body;
>
> my $src = 'C:\image.jpg';
> my $image = $doc->add_file( $src );
>
> use Image::Size;
> my ($w, $h) = Image::Size::imgsize($src);
> $w .= 'pt'; $h .= 'pt';
>
> my $size_image_pt = [$w, $h];
> my $frame = odf_frame->create(
> image => $image,
> size => $size_image_pt,
> description => 'description',
> title => 'title',
> );
>
> my $paragraphe_vide = $contexte->append_element( odf_create_paragraph()
> )->append_element($frame);
> $doc->save(target => "AddFile.odt");
>
> exit;
>
> __END__
>
> The ODT file is created, but Image is empty. I have unzip the ODT file
> Pictures directory contains empty image file (image.jpg : 0Ko).
>
> Best Regards

Another test : ODF::lpOD 1.118 on Win32 XP, perl 5.14 => image_size() and add_file() work in a Windows environment with URL Be careful : $doc->add_image_file('file://c:/path/file.png') OK $doc->add_image_file('file://c:\path\file.png') doest not work. $doc->add_image_file('C:\path\file.png'); doest not work. Le Mer 15 Fév 2012 09:44:12, JMGDOC a écrit : Show quoted text
> OK, the bug looks qualified: > > 1) image_size() and add_file() work in a Unix file system with a Unix > local > file path or a URL); > > 2) image_size() and add_file() work in a Windows environment with URL > but fail > with a local file path. > > > A possible workaround (to be checked) could be a systematic use of > URLs for > local liles, for example: > > $doc->add_image_file('file://c:/path/file.png') > or > $doc->add_image_file('file://c:\path\file.png') > > instead of > > $doc->add_image_file('C:\path\file.png'); > > > As soon as the given source path is recognized as a URL, lpOD > internally uses > LWP to get the resource; so, with a 'file://' prefix systematically > added to > any local file path it's possible (hopefully) to avoid the issu with > Windows > local files. > > > Le 2012-02-15 06:04:00, DJIBEL a écrit :
> > I have tried this program : > > #!/usr/bin/perl > > use Carp; > > use strict; > > use warnings; > > use 5.010_000; > > use ODF::lpOD; > > > > my $doc = odf_document->create('text'); > > my $contexte = $doc->get_body; > > > > my $src = 'C:\image.jpg'; > > my $image = $doc->add_file( $src ); > > > > use Image::Size; > > my ($w, $h) = Image::Size::imgsize($src); > > $w .= 'pt'; $h .= 'pt'; > > > > my $size_image_pt = [$w, $h]; > > my $frame = odf_frame->create( > > image => $image, > > size => $size_image_pt, > > description => 'description', > > title => 'title', > > ); > > > > my $paragraphe_vide = $contexte->append_element(
> odf_create_paragraph()
> > )->append_element($frame); > > $doc->save(target => "AddFile.odt"); > > > > exit; > > > > __END__ > > > > The ODT file is created, but Image is empty. I have unzip the ODT
> file
> > Pictures directory contains empty image file (image.jpg : 0Ko). > > > > Best Regards
Another test : ODF::lpOD 1.117 on Win32 XP, perl 5.14 URL image doest not work (file://) To allow my users which use ODF::lpOD 1.117 or ODF::lpOD 1.118, I have change my code waiting your release like this : if ( $ODF::lpOD::VERSION and $ODF::lpOD::VERSION > 1.117 ) { $src = 'file://' . $src ; $src =~ s{\\}{/}g; } Best Regards, Djibel
Thanks for your investigations. Now the issue is well delimited.

On 2012-02-15 11:23:20, DJIBEL wrote :
Show quoted text
> Another test :
> ODF::lpOD 1.117 on Win32 XP, perl 5.14
>
> URL image doest not work (file://)
>
> To allow my users which use ODF::lpOD 1.117 or ODF::lpOD 1.118, I have
> change my code waiting your release like this :
>
> if ( $ODF::lpOD::VERSION and $ODF::lpOD::VERSION > 1.117 ) {
> $src = 'file://' . $src ;
> $src =~ s{\\}{/}g;
> }
>
> Best Regards,
>
> Djibel

Hello,

There is now a yet unofficial ODF::lpOD 1.119 release, where the image loading and automatic sizing has been reworked.

Could you please check if this release resolves the issue in your environment ?

The package is available here:
http://jean.marie.gouarne.online.fr/tech/lpod/ODF-lpOD-1.119.tar.gz

Thx


Hello, If have tested and ODF::lpOD 1.119 seems to work fine. Good job ! Le Mar 21 Fév 2012 11:02:58, JMGDOC a écrit : Show quoted text
> Hello, > > There is now a yet unofficial ODF::lpOD 1.119 release, where the image > loading > and automatic sizing has been reworked. > > Could you please check if this release resolves the issue in your > environment ? > > The package is available here: > http://jean.marie.gouarne.online.fr/tech/lpod/ODF-lpOD-1.119.tar.gz > > Thx