Create right floating image in PhpWord - php

I want an image on the right, text on the left floating around the image. The other way round works pretty good, there also is an example for that on the Recipies section in the documentation. However, I did not get this working with images floating on the right. What I tried:
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute'
)
);
or
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line'
)
);
I also experimented with negative image widths etc., but that did not work neither. Unfortunately, documentation on the whole project is really poor, at least at phpword.readthedocs.org.

I had the same problem too, and there's no answer on the internet to this date. So here's what I came up with:
$section->addImage('image.png', array(
'width' => 40,
'height' => 40,
'wrappingStyle' => 'square',
'positioning' => 'absolute',
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line',
));

Related

How can I change the aspect ratio of images in php

(I am very new to php, so please forgive my blatant ignorance.)
My portfolio site theme uses this array to display realted images. Currently the theme crops those images to squares. 'images_proportion' => 'marceau_core_image_size_square',
I would like to be able to control the size and proportions of these. Any thoughts on how I might do this would be greatly apreciated.
<div id="qodef-portfolio-single-related-items">
<h4 class="qodef-m-title"><?php echo esc_html__('Related projects', 'marceau-core') ?></h4>
<?php
$params = apply_filters(
'marceau_core_filter_portfolio_single_related_posts_params',
array(
'custom_class' => 'qodef--no-bottom-space',
'columns' => '4',
'posts_per_page' => 4,
'additional_params' => 'id',
'post_ids' => $related_posts['items'],
'layout' => 'info-on-hover',
'hover_animation_info-on-hover' => 'roll-out',
'title_tag' => 'h5',
'behavior' => 'columns',
'images_proportion' => 'marceau_core_image_size_square',
'image_source' => 'featured',
)
);
echo MarceauCore_Portfolio_List_Shortcode::call_shortcode( $params );
?>
</div>
I tried replaceing 'marceau_core_image_size_square' with actual ratios, like '16:9'. And I tried adding height and width to the array, but these megar efforts had no effect.

Full line background color

I´m having a problem with phpword (https://phpword.readthedocs.io/en/latest/index.html)
I want to create a line where all the background is one color (100% width), but I can only make the background the size of the text.
$titleStyle=array('name' => 'Calibri','size' => 11, 'align' =>'center','marginTop' => 10,'bgColor' => 'd0cece');
// Create a new table style
$table_style = new \PhpOffice\PhpWord\Style\Table;
$table_style->setUnit(\PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT);
$table_style->setWidth(100 * 50);
$table_style->setBgColor('d0cece');
// Set up our table.
$tableTitle = $section->addTable($table_style);
$tableTitle->addRow();
$tableTitle->addCell()->addText('Identificação pessoal',$titleStyle);
Someone can help me?
I'm not really familiar with PhpWord, but have you tried to set width of a cell to 100% of document?
$titleStyle = array(
'name' => 'Calibri',
'size' => 11,
'align' =>'center',
'marginTop' => 10,
'bgColor' => 'd0cece',
'width' => 11905.51181102
);
From what I see in the docs, cell width needs to be provided in twip units, which after conversion from 210mm is 11905.51181102 (A4 page width)
https://www.translatorscafe.com/unit-converter/en/typography/1-3/twip-centimeter/

Youtube embed start time convert to time in seconds directly in array from regex group

I want to extend one php package which returns embed code from YouTube. I want to extend it and make embed code with start time querystring.
Piece of Code:
'website' => 'http://youtube.com',
'ssl' => true,
'url' => [
'^(https?://)?(?:www\.)?youtu\.be/([0-9a-zA-Z-_]{11})',
'^(https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:.+&t=)(\S+)',
],
'info' => [
'id' => '{1}',
'url' => '{protocol}://youtu.be/{1}',
'dataUrl' => '{protocol}://gdata.youtube.com/feeds/api/videos/{1}?v=2&alt=jsonc',
'imageRoot' => '{protocol}://img.youtube.com/vi/{1}/',
],
'render' => [
// iframe attributes
'sizeRatio' => 1.77,
'iframe' => [
'src' => '{protocol}://www.youtube.com/embed/{1}?rel=0&wmode=transparent&start={3}',
'width' => 560,
'height' => 315,
'allowfullscreen' => null,
'frameborder' => 0,
],
{3} is a start time from YouTube in format like 1h22m59s or 22m59s or 59s. I am getting {3} from regex from the last group : (?:.+&t=)(\S+)',
Is it possible to run function directly in array value to convert {3} time in seconds? For embed videos I need &start=123 (not ?start=1h22m59s )
I solved it by editing package source. It was the best solution.

QRCode position does not follow the results of previous output in php using library TCPDF

I have a problem with position of qrcode in tcpdf.
First, I want a output of qrcode like this:
but after I added many rows inside of table, qrcode position doesn't follow with my table, like a picture below.
And this is my code
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', 0, 143, 50, 30, $style, 'N');
Please help me, what must I do with this problem.
With gladness, I say thank you for your help.

how to generate thumbnails in CakePHP?

I'am trying to generate thumbnails with uploaded images in CakePHP.
I have worked with Rails and I used paperclip for that purpose, is there any way to do the same with CakePHP?
to be clear, I want to shrink the images keeping the ratio and then crop them in order to get them in the size I want.
If you have PHP available, you can try phpThumb, which does all that for you and much more. It can crop, zoom-crop, transform, blur, contrast...etc etc, and it auto-creates the thumbnails and keeps them in cache so it doesn't have to re-crop...etc each time the image is loaded.
It's also VERY simple to install and use, which is a big plus.
For CakePHP, you can just put the phpthumb folder in your webroot/ directory and use it just like normal.
Sounds like you might be looking for something like my Polyclip plugin. It's not feature-complete so I haven't documented it very well yet (I'll work on that as soon as I can), but it is in production and the core functionality that's in place seems to do what I need. Here's how I have it deployed with an Attraction model.
public $actsAs = array(
'Polyclip.attachable' => array(
'Image' => array(
'Thumbnails' => array(
'medium' => array( 'width' => 250, 'height' => 250, 'method' => 'resize_to_fit' ),
'square' => array( 'width' => 100, 'height' => 100, 'method' => 'resize_to_fill' ),
'sidebar' => array( 'width' => 290, 'height' => 100, 'method' => 'resize_to_fill' )
)
)
)
);
This attaches an image to the attraction with 3 thumbnails created automatically. As I said, it's not documented, but it's out there to fill the need you're looking to fill.

Categories