Problems rotating images

Topics: Developer Forum
Apr 11, 2011 at 8:52 AM

Hi. I am creating a report in PHPExcel and want to attach photographs. Some photos are Landscape and some are Portrait. I want to rotate the Landscape Photographs 90 degrees so that I can get 4 photos to a page. I had hoped the following code would do the job. I scale the photo to the required size and if its Landscape, rotate it, simples!

What actually happens is that the photo 'frame' stays as Landscape but the image inside is rotated and distorts

PHP      = 5.2.10
PHPExcel = 1.7.5

// Photo Section //
if ($photocount > 0) {

	$counter = 0;
	$rowchar = 65; //'A'
	while ($pearl = mysql_fetch_assoc($photos)) {
		$photoid   = $pearl["id"];
		$photoname = "lrg_".$pearl["photo_name"];
		$caption   = $pearl["caption"];
		$orientate = $pearl["orientation"];
		$objPhoto = new PHPExcel_Worksheet_Drawing();
		if ($orientate == 1) {
		if ($counter % 2 == 0) {
			$xlrow += 25;
			$rowchar = 65; //'A'
		} else {
			$rowchar = 67; //'C'
		if ($counter % 4 == 0) { 
			$objPHPExcel->getActiveSheet()->setBreak('A'.$xlrow, PHPExcel_Worksheet::BREAK_ROW);

I have tried the scaling inside the if statement..

if ($orientate == 1) {
} else {


..but get the same result. Any ideas?

May 24, 2011 at 1:13 PM
Edited May 24, 2011 at 1:30 PM

I have just upgraded to PHPExcel 1.7.6 and this still happens.

I have been experimenting with setRotation(x) and have the following results

x = 0 to 44 degrees: Works as expected

x= 135-degrees onwards: Works as expected

But between 45 and 134 degrees the function is broken. The canvas rotates 90 degrees less than requested. The photo image does rotate to the correct angle but is placed in the incorrectly aligned canvas and is stretched to fit. This makes a highly distorted photograph.

I can provide examples if required to effect a fix




May 31, 2011 at 10:10 AM

Which writer do you use ? Excel2007 ? An another ?

May 31, 2011 at 10:28 AM

Yes, forgot to mention, Excel2007. Sorry

// Save Excel file

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); 


May 31, 2011 at 11:35 AM
Yes, Excel2007

Ken Clark
BJA Information Systems
01484 680069

bja Refrigeration Consulting Engineers Ltd. are a company registered in England. No: 5196725

CONFIDENTIALITY NOTICE: The preceding information may be confidential or privileged. It only should be used or disseminated for the purpose of conducting business with bja Refrigeration Consulting Engineers Ltd. If you are not an intended recipient please notify the sender by return email and then delete the information from your system. Thank you for your co-operation.
Nov 27, 2014 at 7:14 AM

I have the same problem as coolken. Is there a workaround to avoid the problem rotating images?