Skip Menu |

This queue is for tickets about the PDF-API2 CPAN distribution.

Report information
The Basics
Id: 132403
Status: open
Priority: 0/
Queue: PDF-API2

People
Owner: Nobody in particular
Requestors: nando.santagata [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Image rotation has a strange effect on its position
Date: Thu, 23 Apr 2020 10:08:47 +0200
To: bug-PDF-API2 [...] rt.cpan.org
From: Fernando Santagata <nando.santagata [...] gmail.com>
Hi, When I first tried to rotate an image using $gfx->rotate(90); I found out that the image was not visible on the page anymore. After a series of attempts I found out that in order to make the image appear on the page I needed to place it outside the visible page, i.e. when I issue the $gfx->image call I have to pass a negative starting x position. I tried this on several images, with the same result. This is the program I'm running: use PDF::API2; my ($output, $file) = @ARGV; my $pdf = PDF::API2->new(-file => $output); my $page = $pdf->page; $page->mediabox('A4'); my $gfx=$page->gfx; $image = $pdf->image_jpeg($file); my $ratio = $image->width / $image->height; my $x1 = 50; my $y1 = -500; # position out of page my $xlen = int(400 * $ratio); my $x2 = $x1 + $xlen; my $y2 = 400; $gfx->rotate(90); $gfx->image($image, $x1, $y1, $x2, $y2); $gfx->close; $gfx->stroke; $pdf->update; $pdf->end; The program works perfectly, it's just that it sounds wrong to have to position the image out of the page. Is there anything I'm missing? I'm using PDF::API2 v2.037 perl v5.30.0 on a Debian sid. Thank you -- Fernando Santagata
I think it's working correctly. You are rotating the page 90 degrees counterclockwise (anti-clockwise) around the current (0,0) origin. As you have not moved the origin, it's at the lower left of the original page, and it remains at the lower left of the rotated page. Therefore the entire original page (+Y) is offscreen to the left, X moves from 0 at the bottom upwards (to the original HEIGHT), and Y is negative over the visible page (0 at left, downwards by the original WIDTH). Therefore, a negative value of Y would be expected. Perhaps you are expecting the origin to shift to the lower RIGHT of the visible page? It doesn't.
A further thought: you may have confused the graphics context "rotate" with the page "rotate" ($page->rotate, done just after defining $page). That one seems to behave more the way you were expecting. I have updated the documentation for both rotate() calls in PDF::Builder, to clarify this.
Subject: Re: [rt.cpan.org #132403] Image rotation has a strange effect on its position
Date: Fri, 24 Apr 2020 07:58:04 +0200
To: bug-PDF-API2 [...] rt.cpan.org
From: Fernando Santagata <nando.santagata [...] gmail.com>
On Fri, Apr 24, 2020 at 3:42 AM Phil M. Perry via RT < bug-PDF-API2@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=132403 > > > A further thought: you may have confused the graphics context "rotate" > with the page "rotate" ($page->rotate, done just after defining $page). > That one seems to behave more the way you were expecting. >
I use both $gfx->rotate and $page->rotate in my original program, because I want to show a landscape image as large as possible and I want to allow the user to see it as easily as possible. I thought that rotating the $gfx would reposition the image, but - as I reported originally - the program works fine so I'm OK. Show quoted text
> I have updated the documentation for both rotate() calls in PDF::Builder, > to clarify this. >
Thank you! -- Fernando Santagata