/** * Generates a printer friendly version of a page * * @param string $content The HTML content of the page * @param string $title The title of the page * @param string $description The description of the page * @param string $pagetitle * @param int $width The width of the page, in pixels */ public static function generate($content, $title = FALSE, $description = FALSE, $pagetitle = FALSE, $width = 680) { $PrintDataBuilder = new self($content, $title, $description); $PrintDataBuilder->setPageTitle($pagetitle); $PrintDataBuilder->setWidth($width); $PrintDataBuilder->render(); }
public static function fromFingerprint($fingerprint) { $array = self::decodeFingerprint($fingerprint); extract($array); $image = new self($s); $image->setWidth($w); $image->setHeight($h); $image->setCrop($c); return $image; }
/** * @param array */ public static function createFromArray(array $params) { $config = new self(); if (isset($params['width'])) { $config->setWidth($params['width']); } if (isset($params['height'])) { $config->setHeight($params['height']); } if (isset($params['fit'])) { $config->setFit($params['fit']); } if (isset($params['quality'])) { $config->setQuality($params['quality']); } }
/** * Parse a page object from a string * * @param string $stream * @return PageObject */ public static function parse($stream) { $page = new self(); $page->setIndex(substr($stream, 0, strpos($stream, ' '))); // Determine the page parent object index. $parent = substr($stream, strpos($stream, '/Parent') + 7); $parent = trim(substr($parent, 0, strpos($parent, '0 R'))); $page->setParentIndex($parent); // Determine the page width and height. $dims = substr($stream, strpos($stream, '/MediaBox') + 9); $dims = substr($dims, 0, strpos($dims, ']')); $dims = trim(str_replace('[', '', $dims)); $dims = explode(' ', $dims); $page->setWidth($dims[2]); $page->setHeight($dims[3]); // Determine the page content objects. if (strpos($stream, '/Contents') !== false) { $contents = substr($stream, strpos($stream, '/Contents') + 9); $contents = $page->getDictionaryReferences($contents); foreach ($contents as $content) { $page->addContentIndex($content); } // Set placeholder $contents = substr($stream, strpos($stream, '/Contents') + 9); if (strpos($contents, '[') !== false) { $contents = substr($contents, 0, strpos($contents, ']') + 1); $stream = str_replace($contents, '[{content_objects}]', $stream); } else { $contents = strpos($contents, '/') !== false ? substr($contents, 0, strpos($contents, '/')) : substr($contents, 0, strpos($contents, '>')); $stream = str_replace($contents, '[{content_objects}]', $stream); } } // If they exist, determine the page annotation objects. if (strpos($stream, '/Annots') !== false) { $annots = substr($stream, strpos($stream, '/Annots') + 7); $annots = $page->getDictionaryReferences($annots); foreach ($annots as $annot) { $page->addAnnotIndex($annot); } // Set placeholder $annots = substr($stream, strpos($stream, '/Annots') + 7); if (strpos($annots, '[') !== false) { $annots = substr($annots, 0, strpos($annots, ']') + 1); $stream = str_replace($annots, '[{annotations}]', $stream); } else { $annots = strpos($annots, '/') !== false ? substr($annots, 0, strpos($annots, '/')) : substr($annots, 0, strpos($annots, '>')); $stream = str_replace($annots, '[{annotations}]', $stream); } } // If they exist, determine the page font references. if (strpos($stream, '/Font') !== false) { $fonts = substr($stream, strpos($stream, 'Font')); $fonts = substr($fonts, 0, strpos($fonts, '>>') + 2); $stream = str_replace('/' . $fonts, '[{fonts}]', $stream); $fonts = str_replace('Font<<', '', $fonts); $fonts = str_replace('>>', '', $fonts); $fonts = explode('/', $fonts); foreach ($fonts as $value) { if ($value != '') { $page->addFontReference('/' . $value); } } } // If they exist, determine the page XObjects references. if (strpos($stream, '/XObject') !== false) { $xo = substr($stream, strpos($stream, 'XObject')); $xo = substr($xo, 0, strpos($xo, '>>') + 2); $stream = str_replace('/' . $xo, '[{xobjects}]', $stream); $xo = str_replace('XObject<<', '', $xo); $xo = str_replace('>>', '', $xo); $xo = explode('/', $xo); foreach ($xo as $value) { if ($value != '') { $page->addXObjectReference('/' . $value); } } } // If they exist, determine the page graphic states. if (strpos($stream, '/ExtGState') !== false) { $gState = substr($stream, strpos($stream, 'ExtGState')); $gState = '/' . substr($gState, 0, strpos($gState, '>>') + 2); } else { $gState = ''; } // If any groups exist if (strpos($stream, '/Group') !== false) { $group = substr($stream, strpos($stream, 'Group')); $group = '/' . substr($group, 0, strpos($group, '>>') + 2); } else { $group = ''; } // If resources exists if (strpos($stream, '/Resources') !== false) { $resources = substr($stream, strpos($stream, 'Resources')); if (strpos($resources, ' R') !== false) { $resources = '/' . substr($resources, 0, strpos($resources, ' R') + 2); } else { if (strpos($resources, '>>') !== false) { $resources = '/' . substr($resources, 0, strpos($resources, '>>') + 2); } else { $resources = "/Resources<</ProcSet[/PDF/Text/ImageB/ImageC/ImageI][{xobjects}][{fonts}]{$gState}>>"; } } } else { $resources = "/Resources<</ProcSet[/PDF/Text/ImageB/ImageC/ImageI][{xobjects}][{fonts}]{$gState}>>"; } if (substr_count($resources, '<<') > substr_count($resources, '>>')) { $resources .= str_repeat('>>', substr_count($resources, '<<') - substr_count($resources, '>>')); } $page->setData("\n[{page_index}] 0 obj\n<</Type/Page/Parent [{parent}] 0 R[{annotations}]/MediaBox" . "[0 0 [{width}] [{height}]]{$group}[{content_objects}]{$resources}>>\nendobj\n"); return $page; }
public static function parseFromString($_string) { $obj = new self(); $tmp = explode(' ', $_string); if (count($tmp) == 1 || $tmp[0] !== 'Region:') { throw new \InvalidArgumentException('Unable to parse the string as WebvttRegion'); } $tmpCount = count($tmp); for ($i = 1; $i < $tmpCount; $i++) { $tmp2 = explode('=', $tmp[$i]); if (count($tmp2) !== 2) { continue; } $tmp2 = array_map('trim', $tmp2); switch ($tmp2[0]) { case 'id': $obj->setId($tmp2[1]); break; case 'width': $obj->setWidth($tmp2[1]); break; case 'lines': $obj->setLines($tmp2[1]); break; case 'regionanchor': $obj->setRegionAnchor($tmp2[1]); break; case 'viewportanchor': $obj->setViewportAnchor($tmp2[1]); break; case 'scroll': $obj->setScroll($tmp2[1]); break; default: break; } unset($tmp2); } return $obj; }
public static function factory($constructedChartData, $loadFromDB = true) { $chartObj = new self(); if (isset($constructedChartData['chart_id'])) { $chartObj->setId((int) $constructedChartData['chart_id']); if ($loadFromDB) { $chartObj->loadFromDB(); $chartObj->prepareData(); $chartObj->shiftStringColumnUp(); } } // Main data (steps 1-3 of chart constructor) $chartObj->setwpDataTableId($constructedChartData['wpdatatable_id']); $chartObj->setTitle($constructedChartData['chart_title']); $chartObj->setEngine($constructedChartData['chart_engine']); $chartObj->setType($constructedChartData['chart_type']); $chartObj->setSelectedColumns($constructedChartData['selected_columns']); $chartObj->setRangeType($constructedChartData['range_type']); if (isset($constructedChartData['range_data'])) { $chartObj->setRowRange($constructedChartData['range_data']); } $chartObj->setFollowFiltering((bool) $constructedChartData['follow_filtering']); // Render data (step 4 or chart constructor) $chartObj->setShowTitle(WDTTools::defineDefaultValue($constructedChartData, 'show_title', '')); $chartObj->setWidth(WDTTools::defineDefaultValue($constructedChartData, 'width', 400)); $chartObj->setHeight(WDTTools::defineDefaultValue($constructedChartData, 'height', 400)); $chartObj->setShowGrid(WDTTools::defineDefaultValue($constructedChartData, 'show_grid', true)); $chartObj->setShowLegend(WDTTools::defineDefaultValue($constructedChartData, 'show_legend', true)); $chartObj->setMajorAxisLabel(WDTTools::defineDefaultValue($constructedChartData, 'horizontal_axis_label', '')); $chartObj->setMinorAxisLabel(WDTTools::defineDefaultValue($constructedChartData, 'vertical_axis_label', '')); if (!empty($constructedChartData['series_data'])) { $chartObj->setUserDefinedSeriesData($constructedChartData['series_data']); } $chartObj->loadChildWPDataTable(); return $chartObj; }
/** * Read from a file * * @deprecated Use img.io.MetaDataReader instead * @param io.File file * @param var default default void what should be returned in case no data is found * @return img.util.ExifData * @throws lang.FormatException in case malformed meta data is encountered * @throws lang.ElementNotFoundException in case no meta data is available * @throws img.ImagingException in case reading meta data fails */ public static function fromFile(File $file) { if (FALSE === getimagesize($file->getURI(), $info)) { $e = new ImagingException('Cannot read image information from ' . $file->getURI()); xp::gc(__FILE__); throw $e; } if (!isset($info['APP1'])) { if (func_num_args() > 1) { return func_get_arg(1); } throw new ElementNotFoundException('Cannot get EXIF information from ' . $file->getURI() . ' (no APP1 marker)'); } if (!($info = exif_read_data($file->getURI(), 'COMPUTED,FILE,IFD0,EXIF,COMMENT,MAKERNOTE', TRUE, FALSE))) { throw new FormatException('Cannot get EXIF information from ' . $file->getURI()); } // Change key case for lookups foreach ($info as &$val) { $val = array_change_key_case($val, CASE_LOWER); } with($e = new self()); // COMPUTED info $e->setWidth(self::lookup($info['COMPUTED'], 'width')); $e->setHeight(self::lookup($info['COMPUTED'], 'height')); $e->setApertureFNumber(self::lookup($info['COMPUTED'], 'aperturefnumber')); // IFD0 info $e->setMake(trim(self::lookup($info['IFD0'], 'make'))); $e->setModel(trim(self::lookup($info['IFD0'], 'model'))); $e->setSoftware(self::lookup($info['IFD0'], 'software')); if (NULL !== ($o = self::lookup($info['IFD0'], 'orientation'))) { $e->setOrientation($o); } else { $e->setOrientation($e->width / $e->height > 1.0 ? 1 : 5); } // FILE info $e->setFileName(self::lookup($info['FILE'], 'filename')); $e->setFileSize(self::lookup($info['FILE'], 'filesize')); $e->setMimeType(self::lookup($info['FILE'], 'mimetype')); // EXIF info $e->setExposureTime(self::lookup($info['EXIF'], 'exposuretime')); $e->setExposureProgram(self::lookup($info['EXIF'], 'exposureprogram')); $e->setMeteringMode(self::lookup($info['EXIF'], 'meteringmode')); $e->setIsoSpeedRatings(self::lookup($info['EXIF'], 'isospeedratings')); // Sometimes white balance is in MAKERNOTE - e.g. FUJIFILM's Finepix if (NULL !== ($w = self::lookup($info['EXIF'], 'whitebalance'))) { $e->setWhiteBalance($w); } else { if (isset($info['MAKERNOTE']) && NULL !== ($w = self::lookup($info['MAKERNOTE'], 'whitebalance'))) { $e->setWhiteBalance($w); } else { $e->setWhiteBalance(NULL); } } // Extract focal length. Some models store "80" as "80/1", rip off // the divisor "1" in this case. if (NULL !== ($l = self::lookup($info['EXIF'], 'focallength'))) { sscanf($l, '%d/%d', $n, $frac); $e->setFocalLength(1 == $frac ? $n : $n . '/' . $frac); } else { $e->setFocalLength(NULL); } // Check for Flash and flashUsed keys if (NULL !== ($f = self::lookup($info['EXIF'], 'flash'))) { $e->setFlash($f); } else { $e->setFlash(NULL); } if (NULL !== ($date = self::lookup($info['EXIF'], 'datetimeoriginal', 'datetimedigitized'))) { $t = sscanf($date, '%4d:%2d:%2d %2d:%2d:%2d'); $e->setDateTime(new Date(mktime($t[3], $t[4], $t[5], $t[1], $t[2], $t[0]))); } return $e; }
/** * 生成静态方法 * * @param int $w 验证码的宽度 * @param int $h 验证码的高度 * @param int $len 验证码的字符数量 */ public static function genImg($w = 130, $h = 80, $len = 4) { $fCaptcha = new self(); $fCaptcha->setWidth($w); $fCaptcha->setHeight($h); $fCaptcha->setLength($len); $fCaptcha->output(); }
/** * Create image from string * @param string $string String of binary image data * @return Image An instance of image */ public static function createFromString($string) { $image = new self(); $imageResource = imagecreatefromstring($string); $image->setImageResource($imageResource); $image->setWidth(imagesx($imageResource)); $image->setHeight(imagesy($imageResource)); $image->setType(IMAGETYPE_UNKNOWN); return $image; }