/** * Get element style * * @param \PhpOffice\PhpWord\Style\Image $style * @return array */ protected function getElementStyle(ImageStyle $style) { $styles = array('mso-width-percent' => '0', 'mso-height-percent' => '0', 'mso-width-relative' => 'margin', 'mso-height-relative' => 'margin'); // Dimension $dimensions = array('width' => $style->getWidth(), 'height' => $style->getHeight(), 'margin-top' => $style->getMarginTop(), 'margin-left' => $style->getMarginLeft()); foreach ($dimensions as $key => $value) { if ($value !== null) { $styles[$key] = $value . 'px'; } } // Absolute/relative positioning $positioning = $style->getPositioning(); $styles['position'] = $positioning; if ($positioning !== null) { $styles['mso-position-horizontal'] = $style->getPosHorizontal(); $styles['mso-position-vertical'] = $style->getPosVertical(); $styles['mso-position-horizontal-relative'] = $style->getPosHorizontalRel(); $styles['mso-position-vertical-relative'] = $style->getPosVerticalRel(); } // Wrapping style $wrapping = $style->getWrappingStyle(); if ($wrapping == ImageStyle::WRAPPING_STYLE_INLINE) { // Nothing to do when inline } elseif ($wrapping == ImageStyle::WRAPPING_STYLE_BEHIND) { $styles['z-index'] = -251658752; } else { $styles['z-index'] = 251659264; $styles['mso-position-horizontal'] = 'absolute'; $styles['mso-position-vertical'] = 'absolute'; } // w10 wrapping if ($wrapping == ImageStyle::WRAPPING_STYLE_SQUARE) { $this->w10wrap = 'square'; } elseif ($wrapping == ImageStyle::WRAPPING_STYLE_TIGHT) { $this->w10wrap = 'tight'; } return $styles; }