/** * * @throws Sitengine_Exception * */ public static function resizePng($inFile, $outFile, $length, $method, $mode = 0644, $transColor = '') { $size = getimagesize($inFile); if (!$size) { throw new Sitengine_Exception('png could not be opened'); } if ($size[2] != 3) { throw new Sitengine_Exception('image is not a png'); } # not a png switch ($method) { case 'width': $width = $length; $height = self::calcHeight($size[0], $size[1], $length); break; case 'height': $width = self::calcWidth($size[0], $size[1], $length); $height = $length; break; default: if ($size[0] > $size[1]) { $width = $length; $height = self::calcHeight($size[0], $size[1], $length); } else { $width = self::calcWidth($size[0], $size[1], $length); $height = $length; } break; } $inRid = imagecreatefrompng($inFile); if (!$inRid) { throw new Sitengine_Exception('png processing error'); } $outRid = imagecreatetruecolor($width, $height); if (!$outRid) { throw new Sitengine_Exception('png processing error'); } $rgbColors = Sitengine_Validator::rgbColor($transColor); if ($rgbColors) { $color = imagecolorallocate($outRid, $rgbColors['red'], $rgbColors['green'], $rgbColors['blue']); $transparency = imagecolortransparent($outRid, $color); } $copy = imagecopyresized($outRid, $inRid, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); if (!$copy) { throw new Sitengine_Exception('png processing error'); } $image = imagepng($outRid, $outFile); if (!$image) { throw new Sitengine_Exception('png processing error'); } chmod($outFile, $mode); $stats = stat($outFile); return array('mime' => 'image/png', 'size' => $stats['size'], 'width' => $width, 'height' => $height); }
protected function _checkUpload($required = false) { $name = 'file1Original'; $upload = new Sitengine_Upload($name); if ($required && !$upload->isFile()) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Required'); $this->_controller->getStatus()->addHint($name, $message); return null; } else { if ($upload->isFile()) { $n = 'transColor'; $v = $this->_controller->getRequest()->getPost($n); if ($v && !Sitengine_Validator::rgbColor($v)) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($n) . 'Invalid'); $this->_controller->getStatus()->addHint($n, $message); } #print $upload->getMime(); if (!preg_match($this->_allowedTypes, $upload->getMime())) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Filetype'); $this->_controller->getStatus()->addHint($name, $message); } if ($upload->getSize() > $this->_maxSize) { $message = $this->_controller->getTranslate()->translate('hints' . ucfirst($name) . 'Filesize'); $this->_controller->getStatus()->addHint($name, $message); } } } }
protected function _checkInput() { $table = $this->_controller->getFrontController()->getProtoPackage()->getShouldiesTable(); $transcripts = $table->getTranscripts(); if ($this->_payloads->isMain() || $this->_payloads->isDefaultTranscript()) { $name = 'titleLang' . $transcripts->getDefaultIndex(); if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name))) { $message = $this->_controller->getTranslate()->translate('hintsTitleRequired'); $this->_controller->getStatus()->addHint($name, $message); } } if ($this->_payloads->isMain()) { $name = 'gid'; if ($this->_controller->getRequest()->getPost($name) == Sitengine_Proto_Backend_Goodies_Shouldies_Controller::VALUE_NONESELECTED) { $message = $this->_controller->getTranslate()->translate('hintsGidRequired'); $this->_controller->getStatus()->addHint($name, $message); } $name = 'type'; if (Sitengine_Validator::nada($this->_controller->getRequest()->getPost($name), Sitengine_Proto_Backend_Goodies_Shouldies_Controller::VALUE_NONESELECTED)) { $message = $this->_controller->getTranslate()->translate('hintsTypeRequired'); $this->_controller->getStatus()->addHint($name, $message); } $fileId = 'file1Original'; $upload = new Sitengine_Upload($fileId); if ($upload->isFile()) { $name = 'transColor'; $val = $this->_controller->getRequest()->getPost($name); if ($val && !Sitengine_Validator::rgbColor($val)) { $message = $this->_controller->getTranslate()->translate('hintsTransColorInvalid'); $this->_controller->getStatus()->addHint($name, $messages); } $messages = array(); if (!preg_match('/(gif|jpg|jpeg|png|pdf|mpeg|quicktime|msword|excel)/i', $upload->getMime())) { $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFiletype'); } if ($upload->getSize() > '1048576') { # 1M $messages[] = $this->_controller->getTranslate()->translate('hintsFile1OriginalFilesize'); } if (sizeof($messages)) { $this->_controller->getStatus()->addHint($fileId, $messages); } } } return !$this->_controller->getStatus()->hasHints(); }