Menu

I need help finding the left x coordinate when I right align an image

Help
2015-11-03
2015-11-04
  • Larene Spitler

    Larene Spitler - 2015-11-03

    $pdf->Image($src, $x, $y, 0, 0, $ext, '', '', true, 300, 'R');

    What is the new x value?

     
  • Simon

    Simon - 2015-11-04

    See GetX() and GetAbsX() in the documentation.

     
  • Simon

    Simon - 2015-11-04

    Sorry. I only just read the subject line.

    I would do some regular PHP to find the dimensions of your image and then do the maths based on the DPI.

    See: http://php.net/manual/en/function.getimagesize.php

     
  • Larene Spitler

    Larene Spitler - 2015-11-04

    I am unfamiliar with the math needed.

     
  • Simon

    Simon - 2015-11-04

    It will be something like:

    $a = $imageWidth/300; //Gives image width in inches;
    $x = $pageWidth - $a - $rightMargin;

    This will work if your default unit is inches, otehrwise you'd need to convert units.

     
  • Larene Spitler

    Larene Spitler - 2015-11-04

    This is what I came up with:

                $x = $pdf->GetX();
                $y = $pdf->GetY();
                if ($float == 'right')
                {
                    $pdf->Image($src, $x,  $y, 0, 0, $ext, '', '', true, 72, 'R');
                    $page = $pdf->getPage();
                    $y = $pdf->GetY();
                    $xb = $pdf->getImageRBX();
                    $yb = $pdf->getImageRBY();
                    $filename = '/home/storytelling/public_html' . $src;
                    list($width, $height, $type, $attr) = getimagesize($filename);
                    $wid = ($width / $pdf->getImageScale()) / $pdf->getScaleFactor();
                    $x = $xb - $wid - 1; // add a space to the left
                    $regions = array();
                    $region = array();
                    $region['page'] = $page;
                    $region['xt'] = $x;
                    $region['yt'] = $y;
                    $region['xb'] = $x;
                    $region['yb'] = $yb;
                    $region['side'] = 'R';
                    array_push($regions, $region);
                    // set page regions, check also getPageRegions(), addPageRegion() and removePageRegion()
                    $pdf->setPageRegions($regions);
                }
    
     

Log in to post a comment.