lib/PHPWord/PHPWord/Media.php
public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null) {
		$mediaId = md5($src);
		$key = ($type == 'image') ? 'images' : 'embeddings';
		
		if(!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
			$cImg = self::countSectionMediaElements('images');
			$cObj = self::countSectionMediaElements('embeddings');
			$rID = self::countSectionMediaElements() + 7;
			
			$media = array();
			
			if($type == 'image') {
				$cImg++;
				$inf = pathinfo($src);
				$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php' && $type == 'image') ? true : false;
				
				if($isMemImage) {
					$ext = $memoryImage->getImageExtension();
					$media['isMemImage'] = true;
					$media['createfunction'] = $memoryImage->getImageCreateFunction();
					$media['imagefunction'] = $memoryImage->getImageFunction();
				} else {
					$ext = $inf['extension'];
					if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
						$ext = 'jpg';
					}
				}
				
				$folder = 'media';
				$file = $type.$cImg.'.'.strtolower($ext);
			} elseif($type == 'oleObject') {
				$cObj++;
				$folder = 'embedding';
				$file = $type.$cObj.'.bin';
			}
			
			$media['source'] = $src;
			$media['target'] = "$folder/section_$file";
			$media['type'] = $type;
			$media['rID'] = $rID;
			
			self::$_sectionMedia[$key][$mediaId] = $media;
			
			if($type == 'oleObject') {
				return array($rID, ++self::$_objectId);
			} else {
				return $rID;
			}
		} else {
			if($type == 'oleObject') {
				$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
				return array($rID, ++self::$_objectId);
			} else {
				return self::$_sectionMedia[$key][$mediaId]['rID'];
			}
		}
	}
public static function addSectionMediaElement($src, $type, PHPWord_Section_MemoryImage $memoryImage = null) {
		$mediaId = md5($src);
		$key = ($type == 'image') ? 'images' : 'embeddings';
		
		if(!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
			$cImg = self::countSectionMediaElements('images');
			$cObj = self::countSectionMediaElements('embeddings');
			$rID = self::countSectionMediaElements() + 7;
			
			$media = array();
			
			if($type == 'image') {
				$cImg++;
				$inf = pathinfo($src);
				$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php' && $type == 'image') ? true : false;
				
				if($isMemImage) {
					$ext = $memoryImage->getImageExtension();
					$media['isMemImage'] = true;
					$media['createfunction'] = $memoryImage->getImageCreateFunction();
					$media['imagefunction'] = $memoryImage->getImageFunction();
				} else {
					$ext = $inf['extension'];
					if($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
						$ext = 'jpg';
					}
				}
				
				$folder = 'media';
				$file = $type.$cImg.'.'.strtolower($ext);
			} elseif($type == 'oleObject') {
				$cObj++;
				$folder = 'embedding';
				$file = $type.$cObj.'.bin';
			}
			
			$media['source'] = $src;
			$media['target'] = "$folder/section_$file";
			$media['type'] = $type;
			$media['rID'] = $rID;
			
			self::$_sectionMedia[$key][$mediaId] = $media;
			
			if($type == 'oleObject') {
				return array($rID, ++self::$_objectId);
			} else {
				return $rID;
			}
		} else {
			if($type == 'oleObject') {
				$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
				return array($rID, ++self::$_objectId);
			} else {
				return self::$_sectionMedia[$key][$mediaId]['rID'];
			}
		}
	}
public static function addSectionMediaElement ( $ src , $ type , PHPWord_Section_MemoryImage $ memoryImage = null ) { $ mediaId = md5 ( $ src ) ; $ key = ( $ type == 'image' ) ? 'images' : 'embeddings' ; if ( ! array_key_exists ( $ mediaId , self :: $ _sectionMedia [ $ key ] ) ) { $ cImg = self :: countSectionMediaElements ( 'images' ) ; $ cObj = self :: countSectionMediaElements ( 'embeddings' ) ; $ rID = self :: countSectionMediaElements ( ) + 7 ; $ media = array ( ) ; if ( $ type == 'image' ) { $ cImg ++ ; $ inf = pathinfo ( $ src ) ; $ isMemImage = ( substr ( strtolower ( $ inf [ 'extension' ] ) , 0 , 3 ) == 'php' && $ type == 'image' ) ? true : false ; if ( $ isMemImage ) { $ ext = $ memoryImage -> getImageExtension ( ) ; $ media [ 'isMemImage' ] = true ; $ media [ 'createfunction' ] = $ memoryImage -> getImageCreateFunction ( ) ; $ media [ 'imagefunction' ] = $ memoryImage -> getImageFunction ( ) ; } else { $ ext = $ inf [ 'extension' ] ; if ( $ ext == 'jpeg' ) { // Office crashes when adding a jpEg Image, so rename to jpg
 $ ext = 'jpg' ; } } $ folder = 'media' ; $ file = $ type . $ cImg . '.' . strtolower ( $ ext ) ; } elseif ( $ type == 'oleObject' ) { $ cObj ++ ; $ folder = 'embedding' ; $ file = $ type . $ cObj . '.bin' ; } $ media [ 'source' ] = $ src ; $ media [ 'target' ] = "$folder/section_$file" ; $ media [ 'type' ] = $ type ; $ media [ 'rID' ] = $ rID ; self :: $ _sectionMedia [ $ key ] [ $ mediaId ] = $ media ; if ( $ type == 'oleObject' ) { return array ( $ rID , ++ self :: $ _objectId ) ; } else { return $ rID ; } } else { if ( $ type == 'oleObject' ) { $ rID = self :: $ _sectionMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; return array ( $ rID , ++ self :: $ _objectId ) ; } else { return self :: $ _sectionMedia [ $ key ] [ $ mediaId ] [ 'rID' ] ; } } }
Add new Section Media Element

@param string $src
@param string $type

@return mixed
Add new Section Media Element