Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image wrappingStyle has no effect #489

Open
donquick opened this issue Mar 8, 2015 · 11 comments
Open

Image wrappingStyle has no effect #489

donquick opened this issue Mar 8, 2015 · 11 comments

Comments

@donquick
Copy link

donquick commented Mar 8, 2015

Hi whatever i put for the wrappingStyle variable in the image style array the image is inline when i open the doc in word. The array is being accessed because other element of the array are being used correctly, but the wrappingStyle is being ignored. After opening the doc, I can right click the image and change the format to 'behind text' or what i want, but I can't control it from the php. Any ideas. Also the marginTop and marginLEft are being ignored, just the width and height are working. Thanks:

$section->addImage('../CMS/images/greenblock.jpg',
        array('wrappingStyle' => 'behind', 'width' => 600, 'height' => 100, 'marginTop' => 3, 'marginLeft' => -1, 'align' => 'center')
    );

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@ComputerTinker
Copy link
Contributor

I was having the same problem, but I noticed that if I told PHPWord to process \samples\Sample_13_Images.php, image wrapping was working fine in the resultant Word document. After a bit of experimentation I found that you must have 'positioning'=>'relative' in your settings array for the image wrapping to work correctly.

@donquick
Copy link
Author

Ahh! - well found - the moment has passed for me actually as i have been round the houses and back with this since then. I am now generating offline and uploading as there were other problems with my project. Hopefully your investigation will help others though. Cheers.

@jmanring
Copy link

jmanring commented Feb 2, 2016

I'm running into the same issue now. I have an image that covers the page and want text to be on top. Everything I try the image is always on top.

$section->addImage('resources/background.png', ['positioning' => 'relative', 'height' => 524, 'width' => 839, 'wrappingStyle' => 'behind']);

@jmanring
Copy link

jmanring commented Feb 2, 2016

So I found that in src/PhpWord/Writer/Word2007/Style/Frame.php if I change:
$zIndices = array(FrameStyle::WRAP_INFRONT => PHP_INT_MAX, FrameStyle::WRAP_BEHIND => -PHP_INT_MAX);
to
$zIndices = array(FrameStyle::WRAP_INFRONT => 251658752, FrameStyle::WRAP_BEHIND => -251658752);
it allows me to set the image to behind in word. What seems to be happening, in my case, is the PHP_INT_MAX equals 9223372036854775807 and my version of Word does not like an integer that large in the xml. By changing that number to the same setting that my Word uses it works.

@playmono
Copy link

Wow, im so lucky that I found this issue. Very thanks @jmanring.

@Bricobit
Copy link

Thanks Jmanring, after many tests the only thing that worked for me is your example, you saved my ass.

I discovered that the command that forces the text to be displayed in front of or behind the image is ->
FBehindDocument - Boolean - Place the shape behind text.
Example: {\ sp {\sn fBehindDocument} {\sv 1}}

Try to implement it inside the class-> PhpWord \ Writer \ Word2007 \ Element \ image.php

But I can not understand PHPWord, too much abstraction and inheritance, in theory that command should be incorporated into the function responsible for creating the style of shape.

Piece of a real document
...0001fffd9}
}}{\sp{\sn posh}{\sv 1}}{\sp{\sn posrelh}{\sv 3}}{\sp{\sn posv}{\sv 1}}{\sp{\sn posrelv}{\sv 3}}{\sp{\sn fBehindDocument}{\sv 1}}{\sp{\sn fPseudoInline}{\sv 0}}{\sp{\sn fLayoutInCell}{\sv 1}}}{\shprslt\par\pard
\ql \li0\ri0\widctlpar\posyt\dxfrtext180\dfrmtxtx180\dfrmtxty0\wraparound\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\pict\picscalex37\picscaley36\piccropl0\piccropr0\piccropt0\piccropb0
\picw47360\pich69189\picwgoal26850\pichgoal39225\wmetafile8\bliptag-2139107557\blipupi6{*\blipuid 807fcf1b05ac0faa3e79e72084be757a}
010009...

In the end after many hours I gave up and use your example, so again thank you very much

@bhavdip111
Copy link

Thanks @jmanring

@djandrew98
Copy link

Hi, I'm still having same issue on setImageValue.

There's my code:
$templateProcessor->setImageValue('image_record', [ 'path' => $local_png, 'width' => 500, 'positioning' => 'reltive', 'wrappingStyle' => 'behind', ]);

But image still not going behind text. In PhpOffice\PhpWord\Writer\Word2007\Style the maxZIndex is 2147483647.

@MAH313
Copy link

MAH313 commented Aug 17, 2020

@djandrew98 try changing your code to:
$templateProcessor->setImageValue('image_record', [ 'path' => $local_png, 'width' => 500, 'positioning' => 'relative', 'wrappingStyle' => 'behind', ]);

Maybe you found this one yourself already but you have relative spelled wrong in your code.

@alensimunic
Copy link

I was having the same problem, but I noticed that if I told PHPWord to process \samples\Sample_13_Images.php, image wrapping was working fine in the resultant Word document. After a bit of experimentation I found that you must have 'positioning'=>'relative' in your settings array for the image wrapping to work correctly.

Why is this still not in documentation?? https://phpword.readthedocs.io/en/latest/styles.html#image-style no positioning mentioned, but it works!!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 18, 2022
@Progi1984 Progi1984 removed the Stale label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

10 participants