Jump to content

Trimming


inspireddesign

Recommended Posts

Hello all.

 

I have a function that inserts an image into an RTF Word document using various control words (below).  My problem is that when the image is inserted I get both the image and the path at which the image is located.

 

So when I open the output document I see ../path/imagename.jpg and the image below.  Is there a way to trim the path from the image that is being inputted?  Thanks for any help on this one.

 

<?php

function add_image($image, $ratio, $align = 'left')
{
	$file = @file_get_contents($image);

	if (empty($file))

		return NULL;

	$image .= "\\ql ";
	$image .= "{";
	$image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 ";
	$image .= trim(bin2hex($file));
	$image .= "\n}\n";
	$image .= "\\par\n";

  		return $image;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/160660-trimming/
Share on other sites

basename():

 

<?php

function add_image($image, $ratio, $align = 'left')
   {
      $file = @file_get_contents($image);
      
      if (empty($file))

         return NULL;

      $image = basename($image);
      $image .= "\\ql ";
      $image .= "{";
      $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 ";
      $image .= trim(bin2hex($file));
      $image .= "\n}\n";
      $image .= "\\par\n";
      
        return $image;
   }

?>

Link to comment
https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847879
Share on other sites

Is there anyway to trim both the path and the filename from the output.  Currently, the below solution trims the path but still leaves the filename with extension.  Learning a whole lot from this forum.  Thanks for everyone's help ;)

 

<?php

function add_image($image, $ratio, $align = 'left')
   {
      $file = @file_get_contents($image);
      
      if (empty($file))

         return NULL;

      $image = basename($image);
      $image .= "\\ql ";
      $image .= "{";
      $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 ";
      $image .= trim(bin2hex($file));
      $image .= "\n}\n";
      $image .= "\\par\n";
      
        return $image;
   }

?>

Link to comment
https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847983
Share on other sites

Oh, you want to remove the whole lot? Then in your original code, start the $image string with "\\ql " instead of concatenating it with the path ('cause $image contains the path to start with):

 

<?php

function add_image($image, $ratio, $align = 'left')
   {
      $file = @file_get_contents($image);
      
      if (empty($file))

         return NULL;

      $image = "\\ql ";
      $image .= "{";
      $image .= "\\pict\\jpegblip\\picscalex". $ratio ."\\picscaley". $ratio ."\\bliptag132000428 ";
      $image .= trim(bin2hex($file));
      $image .= "\n}\n";
      $image .= "\\par\n";
      
        return $image;
   }

?>

Link to comment
https://forums.phpfreaks.com/topic/160660-trimming/#findComment-847997
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.