/** * Fill the product filter with a array. * * @author David Pauli <*****@*****.**> * @since 0.0.1 * @since 0.1.0 Use a default Locale and Currency. * @api * @param String[] $productFilterParameter The values of a product filter. */ public function setProductFilter($productFilterParameter) { if (!InputValidator::isArray($productFilterParameter) || InputValidator::isEmptyArray($productFilterParameter)) { return; } foreach ($productFilterParameter as $key => $parameter) { if ($key == "page") { $this->setPage($parameter); } else { if ($key == "resultsPerPage") { $this->setResultsPerPage($parameter); } else { if ($key == "direction") { $this->setDirection($parameter); } else { if ($key == "sort") { $this->setSort($parameter); } else { if ($key == "q") { $this->setQ($parameter); } else { if ($key == "categoryID") { $this->setCategoryID($parameter); } else { Logger::warning("Unknown attribute <i>" . $key . "</i> in product filter attribute."); } } } } } } } }
/** * @param GenerationThread $thread * @param \Logger $logger * @param \ClassLoader $loader */ public function __construct(GenerationThread $thread, \Logger $logger, \ClassLoader $loader) { $this->thread = $thread; $this->logger = $logger; $this->loader = $loader; $chunkX = $chunkZ = null; while ($this->shutdown !== true) { try { if (count($this->requestQueue) > 0) { foreach ($this->requestQueue as $levelID => $chunks) { if (count($chunks) === 0) { unset($this->requestQueue[$levelID]); } else { $key = key($chunks); if (PHP_INT_SIZE === 8) { $chunkX = $key >> 32 << 32 >> 32; $chunkZ = ($key & 0xffffffff) << 32 >> 32; } else { list($chunkX, $chunkZ) = explode(":", $key); $chunkX = (int) $chunkX; $chunkZ = (int) $chunkZ; } unset($this->requestQueue[$levelID][$key]); $this->generateChunk($levelID, $chunkX, $chunkZ); } } } else { $this->readPacket(); } } catch (\Exception $e) { $this->logger->warning("[Generator Thread] Exception: " . $e->getMessage() . " on file \"" . $e->getFile() . "\" line " . $e->getLine()); } } }
/** * Produces the json to feed the dynamic dropdown * Used by pimcore.object.tags.dynamicDropdown */ public function optionsAction() { $filter = new \Zend_Filter_PregReplace(array("match" => "@[^a-zA-Z0-9/\\-_]@", "replace" => "")); $parentFolderPath = $filter->filter($this->_getParam("source_parent")); if ($parentFolderPath) { // remove trailing slash if ($parentFolderPath != "/") { $parentFolderPath = rtrim($parentFolderPath, "/ "); } // correct wrong path (root-node problem) $parentFolderPath = str_replace("//", "/", $parentFolderPath); $folder = Object_Folder::getByPath($parentFolderPath); if ($folder) { $options = $this->walk_path($folder); } else { Logger::warning("The folder submitted for could not be found: \"" . $this->_getParam("source_parent") . "\""); } } else { Logger::warning("The folder submitted for source_parent is not valid: \"" . $this->_getParam("source_parent") . "\""); } $sort = $this->_getParam("sort_by"); usort($options, function ($a, $b) use($sort) { $field = "id"; if ($sort == "byvalue") { $field = "key"; } if ($a[$field] == $b[$field]) { return 0; } return $a[$field] < $b[$field] ? 0 : 1; }); $this->_helper->json($options); }
public function get_login() { $buf = $this->prefs->get('AuthMethod', 'Token'); $token_url = $buf['url']; $user_node_name = $buf['user_node_name']; $login_attribute_name = $buf['login_attribute_name']; if (!isset($token_url) or $token_url == '') { Logger::error('main', 'Token URL is not defined'); return NULL; } if (!isset($_REQUEST['token'])) { Logger::warning('main', 'Missing parameter : token'); return NULL; } $token_url = str_replace('%TOKEN%', $_REQUEST['token'], $token_url); $xml = query_url($token_url); $dom = new DomDocument('1.0', 'utf-8'); $ret = @$dom->loadXML($xml); if (!$ret) { Logger::error('main', 'Token webservice does not send a valid XML'); return NULL; } $user_node = $dom->getElementsByTagname($user_node_name)->item(0); if (!is_object($user_node)) { Logger::error('main', 'Token webservice does not send a valid XML'); return NULL; } if (!$user_node->hasAttribute($login_attribute_name)) { Logger::error('main', 'Token webservice does not send a valid XML'); return NULL; } $this->login = $user_node->getAttribute($login_attribute_name); return $this->login; }
/** * Moves a file/directory * * @param string $sourcePath * @param string $destinationPath * @return void */ public function move($sourcePath, $destinationPath) { $nameParts = explode("/", $sourcePath); $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]); $sourcePath = implode("/", $nameParts); $nameParts = explode("/", $destinationPath); $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]); $destinationPath = implode("/", $nameParts); try { if (dirname($sourcePath) == dirname($destinationPath)) { try { $destinationNode = $this->getNodeForPath($destinationPath); // If we got here, it means the destination exists, and needs to be overwritten $destinationNode->delete(); } catch (Sabre_DAV_Exception_FileNotFound $e) { // If we got here, it means the destination node does not yet exist Logger::warning("Sabre_DAV_Exception_FileNotFound"); } $asset = Asset::getByPath("/" . $sourcePath); $asset->setFilename(basename($destinationPath)); } else { $asset = Asset::getByPath("/" . $sourcePath); $parent = Asset::getByPath("/" . dirname($destinationPath)); $asset->setPath($parent->getFullPath() . "/"); $asset->setParentId($parent->getId()); } } catch (Exception $e) { Logger::error($e); } $asset->save(); }
/** * @param GenerationThread $thread * @param \Logger $logger * @param \ClassLoader $loader */ public function __construct(GenerationThread $thread, \Logger $logger, \ClassLoader $loader) { $this->thread = $thread; $this->logger = $logger; $this->loader = $loader; $chunkX = $chunkZ = null; while ($this->shutdown !== true) { try { if (count($this->requestQueue) > 0) { foreach ($this->requestQueue as $levelID => $chunks) { if (count($chunks) === 0) { unset($this->requestQueue[$levelID]); } else { Level::getXZ($key = key($chunks), $chunkX, $chunkZ); unset($this->requestQueue[$levelID][$key]); $this->generateChunk($levelID, $chunkX, $chunkZ); } } } else { $this->readPacket(); } } catch (\Exception $e) { $this->logger->warning("[Generator Thread] Exception: " . $e->getMessage() . " on file \"" . $e->getFile() . "\" line " . $e->getLine()); } } }
/** * @param Model\Document $document * @throws \Zend_Json_Exception */ protected function addPropertiesToDocument(Model\Document $document) { // properties if ($this->getParam("properties")) { $properties = array(); // assign inherited properties foreach ($document->getProperties() as $p) { if ($p->isInherited()) { $properties[$p->getName()] = $p; } } $propertiesData = \Zend_Json::decode($this->getParam("properties")); if (is_array($propertiesData)) { foreach ($propertiesData as $propertyName => $propertyData) { $value = $propertyData["data"]; try { $property = new Property(); $property->setType($propertyData["type"]); $property->setName($propertyName); $property->setCtype("document"); $property->setDataFromEditmode($value); $property->setInheritable($propertyData["inheritable"]); $properties[$propertyName] = $property; } catch (\Exception $e) { \Logger::warning("Can't add " . $propertyName . " to document " . $document->getFullPath()); } } } if ($document->isAllowed("properties")) { $document->setProperties($properties); } } // force loading of properties $document->getProperties(); }
public function builder() { if (empty($this->request->get['theme'])) { $this->redirect($this->url->link('settings/themes', '', 'SSL')); exit; } if (empty($this->request->get['store_id'])) { $this->request->get['store_id'] = 0; } $theme = $this->request->get['theme']; $this->document->setTitle(Language::getVar('SUMO_ADMIN_THEMES_BUILDER')); $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SETTINGS_DASHBOARD'), 'href' => $this->url->link('settings/dashboard', '', 'SSL'))); $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_THEMES_SETTINGS'), 'href' => $this->url->link('settings/themes/', '', 'SSL'))); $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_THEMES_BUILDER'))); $this->document->addScript('view/js/jquery/jquery.ajaxupload.js'); $this->data['stores'] = $this->model_settings_stores->getStores(); $this->data['current_store'] = isset($this->request->get['store_id']) ? $this->request->get['store_id'] : 0; if (empty($this->request->get['action'])) { $this->request->get['action'] = 'colors'; } $action = $this->request->get['action']; if (!method_exists($this, $action)) { Logger::warning('It seems ' . $action . ' is not callable?'); $action = 'colors'; } $this->data['action'] = $action; $this->data['theme'] = $theme; $this->data['content'] = $this->{$action}($this->data['current_store'], $this->data['theme']); $this->template = 'settings/themes/builder.tpl'; $this->children = array('common/header', 'common/footer'); //$this->data['content'] = $this->data[$action]; $this->response->setOutput($this->render()); }
/** * Check dependencies * * @param Compiler $compiler */ public function checkDependencies(Compiler $compiler) { $classDefinition = $this->_classDefinition; $extendedClass = $classDefinition->getExtendsClass(); if ($extendedClass) { if ($classDefinition->getType() == 'class') { if ($compiler->isClass($extendedClass)) { $extendedDefinition = $compiler->getClassDefinition($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); } else { if ($compiler->isBundledClass($extendedClass)) { $extendedDefinition = $compiler->getInternalClassDefinition($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending class "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); } } } else { if ($compiler->isInterface($extendedClass)) { $extendedDefinition = $compiler->getClassDefinition($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); } else { if ($compiler->isBundledInterface($extendedClass)) { $extendedDefinition = $compiler->getInternalClassDefinition($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); $this->_logger->warning('Cannot locate class "' . $extendedClass . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); } } } } $implementedInterfaces = $classDefinition->getImplementedInterfaces(); if ($implementedInterfaces) { $interfaceDefinitions = array(); foreach ($implementedInterfaces as $interface) { if ($compiler->isInterface($interface)) { $interfaceDefinitions[$interface] = $compiler->getClassDefinition($interface); } else { if ($compiler->isBundledInterface($interface)) { $interfaceDefinitions[$interface] = $compiler->getInternalClassDefinition($interface); } else { $extendedDefinition = new ClassDefinitionRuntime($extendedClass); $classDefinition->setExtendsClassDefinition($extendedDefinition); $this->_logger->warning('Cannot locate class "' . $interface . '" when extending interface "' . $classDefinition->getCompleteName() . '"', 'nonexistent-class', $this->_originalNode); } } } if ($interfaceDefinitions) { $classDefinition->setImplementedInterfaceDefinitions($interfaceDefinitions); } } }
/** * * @param \Exception|string $e * @throws unknown */ public static function e($e) { if ($e === null || is_string($e)) { Logger::warning($e); throw new \Exception($e); } else { Logger::warning($e->__toString()); throw $e; } }
/** * @param $name */ public static function getByName($name) { try { $config = new self(); $config->setName($name); $config->getDao()->getByName(); return $config; } catch (\Exception $e) { \Logger::warning($e); } }
/** * 设置cache * * @param string $name * @param mixed $var * @param int * @param SerializableFunc $expire_check * @return boolean * 缓存过期检查方法, 缓存过期(超过ttl)后, get时调用, 返回true表示缓存继续可用. * 如checker($got_var, $time) * */ public function set($name, $var, $ttl = 0, $expire_check = null) { $name = $this->tag . $name; $res = $this->impl->set($name, array($var, $ttl, $expire_check, time()), is_null($expire_check) ? $ttl : 0); if (!$res) { Logger::warning("set cache {$name} failed"); } else { Logger::debug("set cache {$name} ok, ttl={$ttl}, check=" . ($expire_check === null ? 'null' : get_class($expire_check))); } return $res; }
/** * Call this function to create a JSON string from a array. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @param mixed[] $array The array to make a JSON. * @return String The JSON string. */ public static function createJSON($array) { if (!InputValidator::isArray($array)) { return null; } $result = json_encode($array); if (!InputValidator::isJSON($result)) { Logger::warning("There is an error with creating a JSON with the following array: <strong>" . json_last_error() . ": " . json_last_error_msg() . "</strong><br/>\n" . "<pre>" . $array . "</pre>"); return null; } return $result; }
/** * Call this function with the JSON in parameter. * * @param String $JSON The JSON string to parse. * @return array The array of the JSON element or null if there is an error. */ public static function parseJSON($JSON) { if (!InputValidator::isJSON($JSON)) { return array(); } $result = json_decode($JSON, true); if (!InputValidator::isArray($result)) { Logger::warning("There is an error with parsing the follwing JSON: <strong>" . json_last_error() . ": " . json_last_error_msg() . "</strong><br/>\n" . "<pre>" . $JSON . "</pre>"); return array(); } return $result; }
public function import($data) { foreach ($data as $class => $rows) { Logger::warning("Import data for {$class}"); $class = __NAMESPACE__ . "\\{$class}"; $model = new $class(); foreach ($rows as $row_data) { $row = $model->newRow(); $row->setValues($row_data); $row->save(); } } }
/** * @return bool */ public function isAvailable() { try { $ffmpeg = self::getFfmpegCli(); $phpCli = Console::getPhpCli(); if ($ffmpeg && $phpCli) { return true; } } catch (\Exception $e) { \Logger::warning($e); } return false; }
/** * @return bool */ public function isAvailable() { try { $ghostscript = self::getGhostscriptCli(); $phpCli = Console::getPhpCli(); if ($ghostscript && $phpCli) { return true; } } catch (\Exception $e) { \Logger::warning($e); } return false; }
/** * Logs a message. * * @param $sMessage @type string The message. */ public function log($sMessage) { $message = date('r') . 'ApnsPHP[' . getmypid() . ']' . trim($sMessage) . '\\n'; if (strpos(trim($sMessage), 'ERROR') !== false) { Logger::error($message); } else { if (strpos(trim($sMessage), 'WARNING') !== false) { Logger::warning($message); } else { Logger::info($message); } } }
/** * @return bool */ public function isAvailable() { try { $lo = self::getLibreOfficeCli(); if ($lo && parent::isAvailable()) { // LibreOffice and GhostScript is necessary return true; } } catch (\Exception $e) { \Logger::warning($e); } return false; }
public static function getTemplate($idOrKey, $language_id = null) { if ($language_id == null || !$language_id) { $language_id = self::$config->get('language_id'); } if (is_string($idOrKey) && !is_numeric($idOrKey)) { $where = 'event_key'; } else { $where = 'mail_id'; } $content = Database::fetchAll("SELECT language_id, title, content, event_key\n FROM PREFIX_mails_content AS mc\n LEFT JOIN PREFIX_mails_to_events AS mte\n ON mc.mail_id = mte.mail_id\n WHERE mte." . $where . " = :input", array('input' => $idOrKey)); if (!$content || !count($content)) { Logger::warning('[Mailer] Template not found for ' . $where . ' ' . $idOrKey); return false; } $data = array(); foreach ($content as $list) { $data[$list['language_id']] = $list; } if (isset($data[$language_id])) { $template = $data[$language_id]; } else { $template = reset($data); } $template['content'] = html_entity_decode($template['content']); $status = null; $event = explode('_', $template['event_key']); if (count($event) == 4) { if ($event[2] == 'status' && !empty($event[3])) { $table = 'PREFIX_' . $event[1] . '_status'; $where = $event[1] . '_status_id'; $id = $event[3]; try { self::$status = Database::query("SELECT " . $where . " AS id, name FROM " . $table . " WHERE " . $where . " = :id AND language_id = :lang", array('id' => $id, 'lang' => $language_id))->fetch(); self::$status['type'] = strtoupper($event[1][0]) . 'ID.'; } catch (\Exception $e) { } } } $toReplace = array(); preg_match_all('/{+(.*?)}/', $template['content'], $toReplace); foreach ($toReplace[1] as $find) { $template['content'] = self::shortcodeReplacement($find, $template['content']); } $toReplace = array(); preg_match_all('/{+(.*?)}/', $template['title'], $toReplace); foreach ($toReplace[1] as $find) { $template['title'] = self::shortcodeReplacement($find, $template['title']); } return $template; }
/** * @param $type * @param $name * @param array $options * @return Tag */ public function tag($type, $name, $options = array()) { $type = strtolower($type); try { // @todo add document-id to registry key | for example for embeded snippets // set suffixes if the tag is inside a block try { $blocks = Zend_Registry::get("pimcore_tag_block_current"); $numeration = Zend_Registry::get("pimcore_tag_block_numeration"); if (is_array($blocks) and count($blocks) > 0) { if ($type == "block") { $tmpBlocks = $blocks; $tmpNumeration = $numeration; array_pop($tmpBlocks); array_pop($tmpNumeration); $tmpName = $name; if (is_array($tmpBlocks)) { $tmpName = $name . implode("_", $tmpBlocks) . implode("_", $tmpNumeration); } if ($blocks[count($blocks) - 1] == $tmpName) { array_pop($blocks); array_pop($numeration); } } $name = $name . implode("_", $blocks) . implode("_", $numeration); } } catch (Exception $e) { } $document = $this->document; if ($document instanceof Document) { $tag = $document->getElement($name); if ($tag instanceof Document_Tag && $tag->getType() == $type) { // call the load() method if it exists to reinitialize the data (eg. from serializing, ...) if (method_exists($tag, "load")) { $tag->load(); } // set view & controller, editmode $tag->setController($this->controller); $tag->setView($this); $tag->setEditmode($this->editmode); $tag->setOptions($options); } else { $tag = Document_Tag::factory($type, $name, $document->getId(), $options, $this->controller, $this, $this->editmode); $document->setElement($name, $tag); } } return $tag; } catch (Exception $e) { Logger::warning($e); } }
/** * Get the data for the object from database for the given id * * @param integer $id * @return void */ public function getById($id) { try { $data = $this->db->fetchRow("SELECT * FROM objects WHERE o_id = ?", $id); if ($data["o_id"]) { $this->assignVariablesToModel($data); $this->getData(); } else { throw new Exception("Object with the ID " . $id . " doesn't exists"); } } catch (Exception $e) { Logger::warning($e); } }
/** * Get the data for the object from database for the given id * * @param integer $id * @return void */ public function getById($id) { try { $data = $this->db->fetchRow("SELECT objects.*, tree_locks.locked as o_locked FROM objects\r\n LEFT JOIN tree_locks ON objects.o_id = tree_locks.id AND tree_locks.type = 'object'\r\n WHERE o_id = ?", $id); if ($data["o_id"]) { $this->assignVariablesToModel($data); $this->getData(); } else { throw new \Exception("Object with the ID " . $id . " doesn't exists"); } } catch (\Exception $e) { \Logger::warning($e); } }
public static function isAvailable() { try { $ffmpeg = Pimcore_Video_Adapter_Ffmpeg::getFfmpegCli(); $phpCli = Pimcore_Tool_Console::getPhpCli(); if (!$ffmpeg || !$phpCli) { throw new Exception("ffmpeg is not available"); } return true; } catch (Exception $e) { Logger::warning($e); } return false; }
public static function getDataFromEditmode($data, $pimcoreTagName) { $tagClass = '\\Pimcore\\Model\\Object\\ClassDefinition\\Data\\' . ucfirst($pimcoreTagName); if (\Pimcore\Tool::classExists($tagClass)) { /** * @var \Pimcore\Model\Object\ClassDefinition\Data $tag */ $tag = new $tagClass(); return $tag->getDataFromEditmode($data); } //purposely return null if there is no valid class, log a warning \Logger::warning("No valid pimcore tag found for fieldType ({$pimcoreTagName}), check 'fieldType' exists, and 'type' is not being used in config"); return null; }
public function get_login() { $buf = $this->prefs->get('AuthMethod', 'Token2'); $tokens = $buf['tokens']; if (!array_key_exists('token', $_REQUEST)) { Logger::warning('main', 'Missing parameter : token'); return NULL; } if (!array_key_exists($_REQUEST['token'], $tokens)) { Logger::warning('main', 'Unauthorized token'); return NULL; } $this->login = $tokens[$_REQUEST['token']]; return $this->login; }
/** * Call this function with the JSON in parameter. * * @author David Pauli <*****@*****.**> * @param String $JSON The JSON string to parse. * @return mixed[] The array of the JSON element or null if there is an error. * @since 0.0.0 * @since 0.1.2 Better the warnings. * @since 0.1.2 Add error reporting. */ public static function parseJSON($JSON) { self::errorReset(); if (!InputValidator::isJSON($JSON)) { Logger::warning("ep6\\JSONHandler\nJSON string (" . $JSON . ") is not valid."); self::errorSet("JSONH-1"); return array(); } $result = json_decode($JSON, true); if (!InputValidator::isArray($result)) { Logger::warning("ep6\\JSONHandler\nThere is an error with parsing the follwing JSON (" . $JSON . "): " . json_last_error() . ": " . json_last_error_msg()); self::errorSet("JSONH-2"); return array(); } return $result; }
/** * Returns the children of the asset if the asset is a folder * * @return array */ function getChildren() { $children = array(); if ($this->asset->hasChilds()) { foreach ($this->asset->getChilds() as $child) { try { if ($child = $this->getChild($child)) { $children[] = $child; } } catch (Exception $e) { Logger::warning($e); } } } return $children; }
public function replace($data = array()) { try { if ($this->model->getId() > 0) { $object = $this->model; } elseif ($data['id'] > 0 and $data['id'] != "") { $object = \Object\Guest::getById($data['id']); } elseif ($data['o_id'] > 0 and $data['o_id'] != "") { $object = \Object\Guest::getById($data['o_id']); } else { $object = $this->model; $date = new \Zend_Date(); $object->setCreationDate($date->get()); //todo $object->setUserOwner(1); $object->setUserModification(1); if (method_exists($object, "setAvatar")) { $object->setAvatar($this->getDefaultImage()); } $object->setPublished(1); } if ($object instanceof \Object\Guest) { $object->setValues($data); $date = new \Zend_Date(); $object->setModificationDate($date); if (!$object->getO_key()) { $folder = $this->getFolderAlpha(); $object->setParent($folder); if (!method_exists($object, getEmail)) { $key1 = $this->model->getClassName(); } else { $key1 = $object->getEmail() ? $object->getEmail() : $this->model->getClassName(); } $numero = $date->get(\Zend_Date::TIMESTAMP); $object_key = $this->correctClassname($key1) . '-' . $numero; $object->setO_key(strtolower($object_key)); } return $object; } else { \Logger::warning("Erreur : Classe de l'objet erronnée"); return false; } } catch (\Exception $e) { \Logger::warning($e->getMessage()); return false; } }
/** * * @param width * @param height * @param default char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($width = 0, $height = 0, $default = '') { if (!$this->info['width'] || !$this->info['height']) { return; } if (!$width) { Logger::warning('Image width is 0!'); $width = $this->info['width']; } if (!$height) { Logger::warning('Image height is 0!'); $height = $this->info['height']; } $xpos = 0; $ypos = 0; $scale = 1; $scale_w = $width / $this->info['width']; $scale_h = $height / $this->info['height']; if ($default == 'w') { $scale = $scale_w; } elseif ($default == 'h') { $scale = $scale_h; } else { $scale = min($scale_w, $scale_h); } if ($scale == 1 && $scale_h == $scale_w && $this->info['mime'] != 'image/png') { return; } $new_width = (int) ($this->info['width'] * $scale); $new_height = (int) ($this->info['height'] * $scale); $xpos = (int) (($width - $new_width) / 2); $ypos = (int) (($height - $new_height) / 2); $image_old = $this->image; $this->image = imagecreatetruecolor($width, $height); $background = imagecolorexact($this->image, 255, 255, 255); if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') { imagecolortransparent($this->image, imagecolorallocatealpha($this->image, 0, 0, 0, 127)); imagealphablending($this->image, false); imagesavealpha($this->image, true); } imagefilledrectangle($this->image, 0, 0, $width, $height, $background); imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']); imagedestroy($image_old); $this->info['width'] = $width; $this->info['height'] = $height; }