PHP Excel image change size

user198003 picture user198003 · Jul 10, 2012 · Viewed 20.1k times · Source

Developing PHP code that will create Excel file using PHP Excel.

I need to place an image into XLS file. Problem I have is that dimension of the image are not the one I defined in my code:

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Water_Level');
$objDrawing->setDescription('Water_Level');
$objDrawing->setPath('img/logo-rab.jpg');
$objDrawing->setHeight(74);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

This image is much higher than 74 pixels. Tried to add height and width also, but always the same.

Can you help me how to add image in my XLS, with dimensions I defined in PHP code?

Thank you in advance!

Answer

Fedy Venom picture Fedy Venom · Oct 1, 2014

Have you tried using setWidthAndHeight and set ResizeProportional true?

$objDrawing->setWidthAndHeight(148,74);
$objDrawing->setResizeProportional(true);