/** * Checks whether sufficient memory is available to load and process an image. */ protected function checkMemory($imagepath) { $memory_available = ShowPlusUtility::memory_get_available(); if ($memory_available !== false) { $imagedata = getimagesize($imagepath); if ($imagedata === false) { return; } if (!isset($imagedata['channels'])) { // assume RGB (i.e. 3 channels) $imagedata['channels'] = 3; } if (!isset($imagedata['bits'])) { // assume 8 bits per channel $imagedata['bits'] = 8; } $memory_required = (int) ceil($imagedata[0] * $imagedata[1] * $imagedata['channels'] * $imagedata['bits'] / 8); if ($memory_required >= $memory_available) { throw new ShowPlusOutOfMemoryException($memory_required, $memory_available, $imagepath); } } }
/** * Short captions attached to images where the labels source is a string. * @return An array of ShowPlusImageLabel instances, or an empty array. */ private function getLabelsFromString($contents) { $contents = str_replace("\r", "\n", $contents); // normalize line endings $matches = array(); preg_match_all('/^([^|\\r\\n]+)(?:[|]([^|\\r\\n]*)(?:[|]([^\\r\\n]*))?)?$/mu', $contents, $matches, PREG_SET_ORDER); switch (preg_last_error()) { case PREG_BAD_UTF8_ERROR: throw new ShowPlusEncodingException($labelsfile); } foreach ($matches as $match) { $imagefile = $match[1]; $hyperlink = false; $caption = false; switch (count($match) - 1) { case 3: $hyperlink = $match[2]; $caption = html_entity_decode($match[3], ENT_QUOTES, 'UTF-8'); break; case 2: if (preg_match('/^(?:https?|ftps?|javascript):/', $match[2])) { // looks like a URL $hyperlink = $match[2]; } else { $caption = html_entity_decode($match[2], ENT_QUOTES, 'UTF-8'); } break; } if ($imagefile == '*') { // set default label if ($hyperlink) { $this->params->deflink = $hyperlink; } if ($caption) { $this->params->defcaption = $caption; } } else { if (ShowPlusUtility::is_remote_path($imagefile)) { // a URL to a remote image $imagefile = ShowPlusUtility::safeurlencode($imagefile); } else { // a local image $imagefile = ShowPlusUtility::file_exists_lenient($this->params->folder . DIRECTORY_SEPARATOR . $imagefile); if ($imagefile === false) { // check that image file truly exists continue; } } $labels[] = new ShowPlusImageLabel($imagefile, $hyperlink, $caption); } } return $labels; }