0

I'm using the PHPPowerPoint lib to generate some powerpoint files. The problem is that the images that are coming from the server are too big, and are breaking the limits of the slide. Here is some code that I'm using for the images:

if(file_exists($dir.$image)){
    // Add logo
    $shape = $slide->createDrawingShape();
    $shape->setName('PHPPowerPoint logo');
    $shape->setDescription('PHPPowerPoint logo');
    $shape->setPath($dir.$image);
    $shape->setWidth(310);
    $shape->setHeight(608);
    $shape->setOffsetX(330);  
    $shape->setOffsetY(70); 
    //$shape->setOffsetY(720 - 10 - 40);
    }

Notice that Im already setting the width and height, but the image is not respecting those configurations. Is there anything that I can do to make the images respect the size that I need or get a responsive behavior?

Edit: This the code for the function createTemplateSlide:

function createTemplatedSlide(PHPPowerPoint $objPHPPowerPoint, $dir, $image, $razao, $nome, $data, $contador)
{
    // Create slide
    $slide = $objPHPPowerPoint->createSlide();

    if(file_exists($dir.$image)){
    // echo("$contador) o arquivo: '".$dir.$image."' existe <br>");
    // Add logo
    $shape = $slide->createDrawingShape();
    $shape->setName('PHPPowerPoint logo');
    $shape->setDescription('PHPPowerPoint logo');
    $shape->setPath($dir.$image);
    $shape->setWidth(310);
    $shape->setHeight(608);
    $shape->setOffsetX(330);  
    $shape->setOffsetY(70); 
    //$shape->setOffsetY(720 - 10 - 40);
    }

    // Create a shape (text)
    // echo date('H:i:s') . " Create a shape (rich text)<br>";
    $shape = $slide->createRichTextShape();
    $shape->setHeight(60);
    $shape->setWidth(960);
    $shape->setOffsetX(0);
    $shape->setOffsetY(20);
    $shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );

    $textRun = $shape->createTextRun($razao."  ".$data);
    $textRun->getFont()->setBold(true);
    $textRun->getFont()->setSize(16);
    $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( '00000000' ) );

    for ($i=0; $i <23 ; $i++) { 
        $shape->createBreak();
    }

    $textRun = $shape->createTextRun(utf8_encode($nome));
    $textRun->getFont()->setBold(true);
    $textRun->getFont()->setSize(16);
    $textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( '00000000' ) );


    // Return slide
    return $slide;
}
churros
  • 199
  • 2
  • 15

1 Answers1

0

Following the suggestion given by @MadeInDreams, I found this topic:

Resize image in PHP

I used the solution there and the function imagejpeg to copy the new generated image to some folder of my project.

churros
  • 199
  • 2
  • 15