/**
  * Create thumbnail for a PDF file
  * @param  string  $source
  * @param  string  $dest
  * @param  integer $width
  * @param  integer $height
  * @param  boolean $shave_all Recommanded when  "image source HEIGHT" < "image source WIDTH"
  * @return boolean
  */
 public static function createPdfThumbnail($source, $dest, $width, $height, $shave_all = false)
 {
     if (class_exists('sfThumbnail') && sfConfig::get('app_sfAssetsLibrary_use_ImageMagick', false) && file_exists($source)) {
         $adapter = 'sfImageMagickAdapter';
         $mime = 'image/jpg';
         if ($shave_all) {
             $thumbnail = new sfThumbnail($width, $height, false, false, 85, $adapter, array('method' => 'shave_all', 'extract' => 0));
         } else {
             list($w, $h) = self::getPdfSize($source);
             $newHeight = $width > 0 && $w > 0 ? ceil($width * $h / $w) : $height;
             $thumbnail = new sfThumbnail($width, $newHeight, true, false, 85, $adapter, array('extract' => 0));
         }
         $thumbnail->loadFile($source);
         $thumbnail->save($dest, $mime, true);
         return true;
     }
     return false;
 }
 protected function updateEmpresaFromRequest()
 {
     $empresa = $this->getRequestParameter('empresa');
     if (isset($empresa['id_provincia'])) {
         $this->empresa->setIdProvincia($empresa['id_provincia'] ? $empresa['id_provincia'] : null);
     }
     if (isset($empresa['id_usuario'])) {
         $this->empresa->setIdUsuario($empresa['id_usuario'] ? $empresa['id_usuario'] : null);
     }
     if (isset($empresa['nombre'])) {
         $this->empresa->setNombre($empresa['nombre']);
     }
     if (isset($empresa['id_actividad'])) {
         $this->empresa->setIdActividad($empresa['id_actividad'] ? $empresa['id_actividad'] : null);
     }
     if (isset($empresa['telefono'])) {
         $this->empresa->setTelefono($empresa['telefono']);
     }
     if (isset($empresa['fax'])) {
         $this->empresa->setFax($empresa['fax']);
     }
     if (isset($empresa['email'])) {
         $this->empresa->setEmail($empresa['email']);
     }
     if (isset($empresa['domicilio'])) {
         $this->empresa->setDomicilio($empresa['domicilio']);
     }
     if (isset($empresa['poblacion'])) {
         $this->empresa->setPoblacion($empresa['poblacion']);
     }
     if (isset($empresa['codigo_postal'])) {
         $this->empresa->setCodigoPostal($empresa['codigo_postal']);
     }
     //SMTP
     if (isset($empresa['smtp_server'])) {
         $this->empresa->setSmtpServer($empresa['smtp_server']);
     }
     if (isset($empresa['smtp_user'])) {
         $this->empresa->setSmtpUser($empresa['smtp_user']);
     }
     if (isset($empresa['smtp_port'])) {
         $this->empresa->setSmtpPort($empresa['smtp_port']);
     }
     if (isset($empresa['change_smtp_password'])) {
         if (isset($empresa['smtp_password'])) {
             $this->empresa->setSmtpPassword($empresa['smtp_password']);
         }
     }
     //SENDER
     if (isset($empresa['sender_address'])) {
         $this->empresa->setSenderAddress($empresa['sender_address']);
     }
     if (isset($empresa['sender_name'])) {
         $this->empresa->setSenderName($empresa['sender_name']);
     }
     $filePath = $this->getRequest()->getFilePath('empresa[imagen]');
     $fileSize = $this->getRequest()->getFileSize('empresa[imagen]');
     $fileExtension = $this->getRequest()->getFileExtension('empresa[imagen]');
     $fileType = $this->getRequest()->getFileType('empresa[imagen]');
     $fileError = $this->getRequest()->hasFileError('empresa[imagen]');
     $nombre_foto = $this->getRequest()->getFileName('empresa[imagen]');
     if ($nombre_foto != '') {
         $filename_min = md5(uniqid("logo")) . $fileExtension;
         $width_min = sfConfig::get('app_logos_min_size_width');
         $height_min = sfConfig::get('app_logos_min_size_height');
         $thumbnail_min = new sfThumbnail($width_min, $height_min);
         $thumbnail_min->loadFile($filePath);
         $thumbnail_min->save(sfConfig::get('app_directorio_logos') . $filename_min, $fileType);
         $filename_med = md5(uniqid("foto")) . $fileExtension;
         $width_med = sfConfig::get('app_logos_med_size_width');
         $height_med = sfConfig::get('app_logos_med_size_height');
         $thumbnail_med = new sfThumbnail($width_med, $height_med);
         $thumbnail_med->loadFile($filePath);
         $thumbnail_med->save(sfConfig::get('app_directorio_logos') . $filename_med, $fileType);
         $filename_max = md5(uniqid("foto")) . $fileExtension;
         $width_max = sfConfig::get('app_logos_max_size_width');
         $height_max = sfConfig::get('app_logos_max_size_height');
         $thumbnail_max = new sfThumbnail($width_max, $height_max);
         $thumbnail_max->loadFile($filePath);
         $thumbnail_max->save(sfConfig::get('app_directorio_logos') . $filename_max, $fileType);
         $old_logo_min = $this->empresa->getUrlLogoMin() ? $this->empresa->getUrlLogoMin() : null;
         $old_logo_med = $this->empresa->getUrlLogoMed() ? $this->empresa->getUrlLogoMed() : null;
         $old_logo_max = $this->empresa->getUrlLogoMax() ? $this->empresa->getUrlLogoMax() : null;
         $this->empresa->setLogoMin($filename_min);
         $this->empresa->setLogoMed($filename_med);
         $this->empresa->setLogoMax($filename_max);
     }
     //SMS
     if (isset($empresa['sms_user'])) {
         $this->empresa->setSmsUser($empresa['sms_user']);
     }
     if (isset($empresa['change_sms_password'])) {
         if (isset($empresa['sms_password'])) {
             $this->empresa->setSmsPass($empresa['sms_password']);
         }
     }
     if (isset($empresa['sms_num_dias'])) {
         $this->empresa->setSmsNumDias($empresa['sms_num_dias']);
     }
     //COLORES
     if (isset($empresa['color1'])) {
         $this->empresa->setColor1($empresa['color1']);
     }
     if (isset($empresa['color2'])) {
         $this->empresa->setColor2($empresa['color2']);
     }
     if (isset($empresa['color3'])) {
         $this->empresa->setColor3($empresa['color3']);
     }
     if (isset($empresa['color4'])) {
         $this->empresa->setColor4($empresa['color4']);
     }
     if (isset($empresa['colorletra1'])) {
         $this->empresa->setColorLetra1($empresa['colorletra1']);
     }
     if (isset($empresa['colorletra2'])) {
         $this->empresa->setColorLetra2($empresa['colorletra2']);
     }
     if (isset($empresa['colorletra3'])) {
         $this->empresa->setColorLetra3($empresa['colorletra3']);
     }
     if (isset($empresa['colorletra4'])) {
         $this->empresa->setColorLetra4($empresa['colorletra4']);
     }
 }
示例#3
0
 public static function saveMedia($file, $parentId, $type, $className, $isMain)
 {
     if ($file['name']) {
         $media = new Media();
         $media->setParentId($parentId);
         $media->setType($type);
         $media->setClassName($className);
         $media->setPath($file['name']);
         //retrive file extention
         $fileNameArr = explode('.', $file['name']);
         $fileExt = end($fileNameArr);
         $media->setExt($fileExt);
         if ($isMain) {
             $media->setIsMain(1);
         }
         $media->save();
         //Save file
         if ($type == MediaPeer::IMAGE) {
             // resize image
             $image = new sfThumbnail(800, 800);
             $image->loadFile($file['tmp_name']);
             //$image->save(sfConfig::get('sf_upload_dir')."/$parentId/".$file['name'], 'image/jpeg');
             $image->save(sfConfig::get('sf_upload_dir') . "/" . $media->getId() . "." . $media->getExt());
             // create thunmbnail
             $imageTh = new sfThumbnail(80, 80);
             $imageTh->loadFile($file['tmp_name']);
             $imageTh->save(sfConfig::get('sf_upload_dir') . "/th_" . $media->getId() . "." . $media->getExt());
         }
     }
 }
示例#4
0
/**
 * Get the path of a generated thumbnail for any given image
 *
 * @param string $source
 * @param int $width
 * @param int $height
 * @param boolean $absolute
 * @return string
 */
function thumbnail_path($source, $width, $height, $absolute = false)
{
    $thumbnails_dir = sfConfig::get('app_sfThumbnail_thumbnails_dir', 'uploads/thumbnails');
    $width = intval($width);
    $height = intval($height);
    if (substr($source, 0, 1) == '/') {
        $realpath = sfConfig::get('sf_web_dir') . $source;
    } else {
        $realpath = sfConfig::get('sf_web_dir') . '/images/' . $source;
    }
    $real_dir = dirname($realpath);
    $thumb_dir = '/' . $thumbnails_dir . substr($real_dir, strlen(sfConfig::get('sf_web_dir')));
    $thumb_name = preg_replace('/^(.*?)(\\..+)?$/', '$1_' . $width . 'x' . $height . '$2', basename($source));
    $img_from = $realpath;
    $thumb = $thumb_dir . '/' . $thumb_name;
    $img_to = sfConfig::get('sf_web_dir') . $thumb;
    if (!is_dir(dirname($img_to))) {
        if (!mkdir(dirname($img_to), 0777, true)) {
            throw new Exception('Cannot create directory for thumbnail : ' . $img_to);
        }
    }
    if (!is_file($img_to) || filemtime($img_from) > filemtime($img_to)) {
        $thumbnail = new sfThumbnail($width, $height);
        $thumbnail->loadFile($img_from);
        $thumbnail->save($img_to);
    }
    return image_path($thumb, $absolute);
}
示例#5
0
 public function save(PropelPDO $con = null, $value = null)
 {
     if ($this->getFileType() == 1) {
         if (!file_exists(sfConfig::get('upload_dir') . '/original')) {
             mkdir(sfConfig::get('upload_dir') . '/original', 0777);
         }
         move_uploaded_file($value['tmp_name'], sfConfig::get('upload_dir') . '/original/' . $this->getName());
         if ($value) {
             list($width, $height) = getimagesize(sfConfig::get('upload_dir') . '/original/' . $this->getName());
             foreach (sfConfig::get('images_format') as $format) {
                 @(list($new_width, $new_height) = explode('x', $format));
                 if ($width > $new_width) {
                     if (!file_exists(sfConfig::get('upload_dir') . '/' . $format)) {
                         mkdir(sfConfig::get('upload_dir') . '/' . $format, 0777);
                     }
                     if (isset($new_height)) {
                         $thumbnail = new sfThumbnail($new_width, $new_height, false, false, 75, 'sfImageMagickAdapter', array('method' => 'shave_all'));
                     } else {
                         $thumbnail = new sfThumbnail($new_width);
                     }
                     $thumbnail->loadFile(sfConfig::get('upload_dir') . '/original/' . $this->getName());
                     $thumbnail->save(sfConfig::get('upload_dir') . '/' . $format . '/' . $this->getName());
                 }
             }
         }
     } else {
         if (!file_exists(sfConfig::get('upload_dir') . '/doc')) {
             mkdir(sfConfig::get('upload_dir') . '/doc', 0777);
         }
         move_uploaded_file($value['tmp_name'], sfConfig::get('upload_dir') . '/doc/' . $this->getName());
     }
     parent::save();
 }
 public static function resizeImage($mx, $my, $filename, $olddir, $newdir = false)
 {
     if (!$newdir) {
         $newdir = $olddir;
     }
     $thumbnail = new sfThumbnail($mx, $my, false, true, 100, 'sfImageMagickAdapter', array('method' => 'shave_all'));
     $thumbnail->loadFile($olddir . $filename);
     $thumbnail->save($newdir . $filename, 'image/png');
 }
示例#7
0
 public static function genThumbnail($mx, $my, $upload_dir, $fileName, $fileNameNew = "")
 {
     try {
         if (!$fileNameNew) {
             $fileNameNew = $fileName;
         }
         $thumbnail = new sfThumbnail($mx, $my, false, true, 75, 'sfImageMagickAdapter', array('method' => 'shave_all'));
         $thumbnail->loadFile($upload_dir . $fileName);
         $thumbnail->save(sfConfig::get('sf_upload_dir') . '/thumbnails/' . $fileNameNew, 'image/png');
     } catch (Exception $e) {
     }
 }
示例#8
0
 /**
  * Resizes an image.
  * if $square = true, make resulting image square
  */
 public static function generateThumbnail($name, $ext, $path, $dimensions, $suffix, $square = false, $inflate = false, $strip = false, $progressive = false)
 {
     $path = $path . DIRECTORY_SEPARATOR;
     $adapter = sfConfig::get('app_images_tool') === 'imagemagick' ? 'sfImageMagickAdapter' : 'sfGDAdapter';
     // delete thumbnail if already exists
     self::remove($path . $name . $suffix . $ext);
     // we pass maximum height and width dimensions,
     // say that we preserve aspect ratio (scale=true), and that we do not want to inflate (inflate=false), and quality = 85%
     $thumbnail = new sfThumbnail($dimensions['width'], $dimensions['height'], true, $inflate, $square, 85, $adapter, array('keep_source_enable' => true, 'strip' => $strip, 'progressive' => $progressive));
     $thumbnail->loadFile($path . $name . $ext);
     $thumbnail->save($path . $name . $suffix . $ext);
 }
示例#9
0
 /**
  * create thumbnail using sfThumbnail plugin
  *
  * @param string $src
  * @param string $dst
  * @param integer $maxWidth
  * @param integer $maxHeight
  * @param integer $scale
  * @param integer $inflate
  * @param Array $transparency
  * @param integer $quality
  * @return mixed thumbnail
  */
 public static function resample($src, $dst = false, $maxWidth = 80, $maxHeight = 80, $scale = true, $inflate = true, $transparency = array('red' => 255, 'green' => 255, 'blue' => 255), $quality = 75)
 {
     $thumbnail = new sfThumbnail($maxWidth, $maxHeight);
     $thumbnail->loadFile($src);
     if ($dst) {
         //if dst is a filename (string) then write the resampled image to that file. if it's TRUE (boolean) write the thumb to the same file. if it's FALSE (boolean) return the resource
         if (is_bool($dst)) {
             $dst = $src;
         }
         $thumbnail->save($dst);
     } else {
         return $thumbnail;
     }
 }
示例#10
0
 /**
  * Saves the uploaded file.
  *
  * This method can throw exceptions if there is a problem when saving the file.
  *
  * If you don't pass a file name, it will be generated by the generateFilename method.
  * This will only work if you have passed a path when initializing this instance.
  *
  * @param  string $file      The file path to save the file
  * @param  int    $fileMode  The octal mode to use for the new file
  * @param  bool   $create    Indicates that we should make the directory before moving the file
  * @param  int    $dirMode   The octal mode to use when creating the directory
  *
  * @return string The filename without the $this->path prefix
  *
  * @throws Exception
  */
 public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
 {
     if (is_null($file)) {
         $file = $this->generateFilename();
     }
     if ($file[0] != '/' && $file[0] != '\\' && !(strlen($file) > 3 && ctype_alpha($file[0]) && $file[1] == ':' && ($file[2] == '\\' || $file[2] == '/'))) {
         if (is_null($this->path)) {
             throw new RuntimeException('You must give a "path" when you give a relative file name.');
         }
         $smallFile = $this->path . DIRECTORY_SEPARATOR . 's_' . $file;
         $file = $this->path . DIRECTORY_SEPARATOR . $file;
     }
     // get our directory path from the destination filename
     $directory = dirname($file);
     if (!is_readable($directory)) {
         if ($create && !mkdir($directory, $dirMode, true)) {
             // failed to create the directory
             throw new Exception(sprintf('Failed to create file upload directory "%s".', $directory));
         }
         // chmod the directory since it doesn't seem to work on recursive paths
         chmod($directory, $dirMode);
     }
     if (!is_dir($directory)) {
         // the directory path exists but it's not a directory
         throw new Exception(sprintf('File upload path "%s" exists, but is not a directory.', $directory));
     }
     if (!is_writable($directory)) {
         // the directory isn't writable
         throw new Exception(sprintf('File upload path "%s" is not writable.', $directory));
     }
     // copy the temp file to the destination file
     //		$thumbnail = new sfThumbnail(100, 100, true, true, 85, 'sfGDAdapterCuttingOff');
     //		$thumbnail->loadFile($this->getTempName());
     //		$thumbnail->save($smallFile, 'image/jpeg');
     $thumbnail = new sfThumbnail(50, 50, true, false, 100, sfConfig::get('app_sfThumbnailPlugin_adapter', 'sfGDAdapter'));
     $thumbnail->loadFile($this->getTempName());
     $thumbnail->save($file);
     // chmod our file
     //		chmod($smallFile, $fileMode);
     chmod($file, $fileMode);
     $this->savedName = $file;
     return is_null($this->path) ? $file : str_replace($this->path . DIRECTORY_SEPARATOR, '', $file);
 }
示例#11
0
 /**
  * Here I'm making deleting the old file on save if it exists, makingthe filename, and setting the filename in the database on save
  */
 public function doSave($con = null)
 {
     if ($this->getValue('picture')) {
         if ($this->getObject()->getPicture() != '' && file_exists(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $this->getObject()->getPicture())) {
             unlink(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $this->getObject()->getPicture());
         }
         $file = $this->getValue('picture');
         $filename = sha1($file->getOriginalName()) . $file->getExtension($file->getOriginalExtension());
         $file->save(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $filename);
         //create thumbnail here
         $thumbnail = new sfThumbnail(120, 160, false, true, 75, 'sfImageMagickAdapter', array('method' => 'shave_all'));
         $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $filename);
         $thumbnail->save(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $filename);
     }
     if ($this->getValue('picture_delete')) {
         if ($this->getObject()->getPicture() != 'picture_missing.jpg' && file_exists(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $this->getObject()->getPicture())) {
             unlink(sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_employee_images_dir', 'employee') . '/' . $this->getObject()->getPicture());
         }
     }
     return parent::doSave($con);
 }
示例#12
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeUpload(sfWebRequest $request)
 {
     $uploaded_file = $request->getFiles('file');
     $this->filename = '';
     if ($uploaded_file) {
         try {
             $pathinfo = pathinfo($uploaded_file['name']);
             $name = time() . rand(1, 999999);
             $extension = $pathinfo["extension"] ? $pathinfo["extension"] : "jpg";
             $filename = $name . "." . $extension;
             $origin = $name . "_origin." . $extension;
             $thumbnail = new sfThumbnail(811, 0, true, false, 100, sfConfig::get('app_sfThumbnailPlugin_adapter', 'sfGDAdapter'));
             $thumbnail->loadFile($uploaded_file['tmp_name']);
             $thumbnail->save(sfConfig::get('sf_upload_dir') . '/' . $filename);
             move_uploaded_file($uploaded_file['tmp_name'], sfConfig::get('sf_upload_dir') . '/' . $origin);
             $this->filename = 'http://' . $request->getHost() . '/uploads/' . $filename;
         } catch (Exception $e) {
         }
     }
     return $this->renderPartial('upload', array('filename' => $this->filename));
 }
示例#13
0
 public function executeDo(sfWebRequest $request)
 {
     $file = $request->getFiles('upload_file');
     $fname = md5(time());
     $picture = '/uploads/' . $fname . '.jpg';
     if (move_uploaded_file($file['tmp_name'], sfConfig::get('upload_dir') . '/tmp/' . $fname . '.jpg')) {
         list($width, $height, $type, $attr) = getimagesize(sfConfig::get('upload_dir') . '/tmp/' . $fname . '.jpg');
         if ($width > sfConfig::get('image_width')) {
             $thumbnail = new sfThumbnail(sfConfig::get('image_width'));
             $thumbnail->loadFile(sfConfig::get('upload_dir') . '/tmp/' . $fname . '.jpg');
             $thumbnail->save(sfConfig::get('upload_dir') . '/' . $fname . '.jpg');
         } else {
             copy(sfConfig::get('upload_dir') . '/tmp/' . $fname . '.jpg', sfConfig::get('upload_dir') . '/' . $fname . '.jpg');
         }
     }
     if (!in_array($picture, array(self::ERROR_UPLOADING, self::ERROR_MIME))) {
         $this->redirect = 'upload/image?media_url=' . base64_encode(strval($picture));
     } else {
         $this->redirect = 'upload/image?error=' . $picture;
     }
 }
示例#14
0
 static function writeAvatarImage($sourceFile, $userId)
 {
     $destinationDir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_general_avatar_folder');
     if (!file_exists($destinationDir)) {
         mkdir($destinationDir, 0700, true);
     }
     $destinationFile = $destinationDir . DIRECTORY_SEPARATOR . $userId;
     // create thumb
     $thumb = new sfThumbnail(sfConfig::get('app_general_avatar_max_width'), sfConfig::get('app_general_avatar_max_height'));
     $thumb->loadFile($sourceFile);
     $thumb->save($destinationFile, 'image/jpeg');
     $thumb = new sfThumbnail(sfConfig::get('app_general_avatar_max_width2'), sfConfig::get('app_general_avatar_max_height2'));
     $thumb->loadFile($sourceFile);
     $thumb->save($destinationFile . "_2", 'image/jpeg');
     $thumb = new sfThumbnail(sfConfig::get('app_general_avatar_max_width3'), sfConfig::get('app_general_avatar_max_height3'));
     $thumb->loadFile($sourceFile);
     $thumb->save($destinationFile . "_3", 'image/jpeg');
     $thumb = new sfThumbnail(sfConfig::get('app_general_avatar_max_width4'), sfConfig::get('app_general_avatar_max_height4'));
     $thumb->loadFile($sourceFile);
     $thumb->save($destinationFile . "_4", 'image/jpeg');
 }
示例#15
0
 private function addBot(BotNick $nick, $dateBorn, BotData $data = null)
 {
     $bot = new sfGuardUser();
     $botProfile = new sfGuardUserProfile();
     $botProfile->setUser($bot);
     $Bot = new Bot();
     $bot->username = $nick->nick;
     $bot->email_address = ($data ? $data->uid : md5($nick->nick . "uberlov mail")) . "@uberlov.ru";
     $bot->created_at = $dateBorn;
     $bot->updated_at = $dateBorn;
     $bot->last_login = $dateBorn;
     if (!empty($data)) {
         if (isset($data->userpic) && strstr($data->userpic, 'jpg')) {
             $userpic = new sfThumbnail(48, 48, false);
             $userpic->loadFile("Z:/home/ht/www/images/userpic/bot/" . $data->userpic);
             $name = md5($data->uid . 'userpic f**k yea') . '.png';
             $userpic->save(sfConfig::get('sf_user_pic_dir') . $name, 'image/png');
             $botProfile->userpic = $name;
         }
         if (isset($data->name)) {
             $names = explode(" ", $data->name);
             $bot->last_name = isset($names[1]) ? $names[1] : "";
             $bot->first_name = isset($names[0]) ? $names[0] : "";
         }
         $Bot->setBotDataId($data->id);
         $this->activeBots->add($bot);
     }
     $botProfile->sex = 1;
     $botProfile->validate_at = $dateBorn;
     $botProfile->created_at = $dateBorn;
     $botProfile->updated_at = $dateBorn;
     $bot->save();
     $botProfile->save();
     $Bot->setBotNickId($nick->id);
     $Bot->setProfileId($botProfile->id);
     $Bot->save();
     $this->totalBots++;
 }
示例#16
0
 public static function UploadRemote($url)
 {
     $parsedUrl = parse_url($url);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; GoogleToolbar 2.0.111-big; Windows NT 5.1; ru; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14 WebMoney Advisor');
     curl_setopt($curl, CURLOPT_AUTOREFERER, true);
     curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
     curl_setopt($curl, CURLOPT_REFERER, $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/');
     $image = curl_exec($curl);
     $mime = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
     $filename = pathinfo($url);
     $extension = $filename["extension"] ? $filename["extension"] : "jpg";
     $filename = time() . rand(1, 999999) . "." . $extension;
     $thumbnail = new sfThumbnail(811, 0, true, false, 100, sfConfig::get('app_sfThumbnailPlugin_adapter', 'sfGDAdapter'));
     $tempFile = tempnam('/tmp', '');
     file_put_contents($tempFile, $image);
     $thumbnail->loadFile($tempFile);
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/' . $filename);
     unlink($tempFile);
     return $filename;
 }
 public static function calculateWidthAndHeight(sfImagePoolImage $image, $w, $h)
 {
     $sfthumb = new sfThumbnail($w, $h, true, sfConfig::get('app_sf_image_pool_inflate', true));
     $sfthumb->loadFile($image->getPathToOriginalFile());
     $response = array($sfthumb->getThumbWidth(), $sfthumb->getThumbHeight());
     unset($sfthumb);
     return $response;
 }
 /**
  * Resize automatically an image
  * @param  string  $source
  * @param  string  $dest
  * @param  integer $width
  * @param  integer $height
  * @param  boolean $shave_all Recommanded when  "image source HEIGHT" < "image source WIDTH"
  * @return boolean
  */
 public static function createThumbnail($source, $dest, $width, $height, $shave_all = false)
 {
     if (class_exists('sfThumbnail') && file_exists($source)) {
         if (sfConfig::get('app_sfAssetsLibrary_use_ImageMagick', false)) {
             $adapter = 'sfImageMagickAdapter';
             $mime = 'image/jpg';
         } else {
             $adapter = 'sfGDAdapter';
             $mime = 'image/jpeg';
         }
         if ($shave_all) {
             $thumbnail = new sfThumbnail($width, $height, false, true, 85, $adapter, array('method' => 'shave_all'));
             $thumbnail->loadFile($source);
             $thumbnail->save($dest, $mime);
             return true;
         } else {
             list($w, $h, $type, $attr) = getimagesize($source);
             $newHeight = $width ? ceil($width * $h / $w) : $height;
             $thumbnail = new sfThumbnail($width, $newHeight, true, true, 85, $adapter);
             $thumbnail->loadFile($source);
             $thumbnail->save($dest, $mime);
             return true;
         }
     }
     return false;
 }
 /**
  * Execute generateThumbnailImage function generate thumbnail image of image
  * 
  * @param $ssImageName = image name 
  * @param $ssThumbnailImage = thumbnail image name
  * @param $snWidth = width of thumbnail image 
  * @param $snHeight = height of thumbnail image
  * @param $ssType = type of thumbnail image  
  */
 public static function generateThumbnailImage($ssImageName, $ssThumbnailImage, $snWidth, $snHeight, $ssType)
 {
     $omThumbnail = new sfThumbnail($snWidth, $snHeight, true, true);
     $omThumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/' . $ssImageName);
     $omThumbnail->save(sfConfig::get('sf_upload_dir') . '/' . $ssThumbnailImage, $ssType);
 }
 /**
  * Generate a thumbnail of a given type.
  * 
  * @param <type> $thumb_type thumbnail type
  * @param <type> $thumb_options thumbnail options (width, height and other as set in configuration).
  * @return bool true = success, false = failure.
  */
 protected function generateThumbnail($thumb_type, $thumb_options)
 {
     $source = $this->folder . $this->file;
     $dest = $this->getThumbnailPath($thumb_type);
     $width = $thumb_options['width'];
     $height = $thumb_options['height'];
     $shave_all = isset($thumb_options['shave']) ? $thumb_options['shave'] : false;
     if (class_exists('sfThumbnail') && file_exists($source)) {
         if (sfConfig::get('app_lyMediaManager_use_ImageMagick', false)) {
             $adapter = 'sfImageMagickAdapter';
             $mime = 'image/jpg';
         } else {
             $adapter = 'sfGDAdapter';
             $mime = 'image/jpeg';
         }
         if ($shave_all) {
             $thumbnail = new sfThumbnail($width, $height, false, true, 85, $adapter, array('method' => 'shave_all'));
             $thumbnail->loadFile($source);
             $thumbnail->save($dest, $mime);
             return true;
         } else {
             list($w, $h, $type, $attr) = getimagesize($source);
             $newHeight = $width ? ceil($width * $h / $w) : $height;
             $thumbnail = new sfThumbnail($width, $newHeight, true, true, 85, $adapter);
             $thumbnail->loadFile($source);
             $thumbnail->save($dest, $mime);
             return true;
         }
     }
     return false;
 }
示例#21
0
 public function executeInsert()
 {
     $user = $this->getContext()->getInstance()->getUser();
     $referer = $user->getAttribute('referer', $this->getRequest()->getReferer());
     // Qui ci arrivo solo se ho passato il validate
     // Quindi non devo fare controlli ...
     $file_name = $this->getRequest()->getFileName('file');
     $file_info = $this->getRequest()->getFile('file');
     $type = $file_info['type'];
     // Trova il suffisso (jpg,gif,png)
     if (eregi('gif', $type)) {
         $suffix = 'gif';
     }
     if (eregi('jpg|jpeg', $type)) {
         $suffix = 'jpg';
     }
     if (eregi('png', $type)) {
         $suffix = 'png';
     }
     // Operazioni per il DB
     $photo = new sfPhotoGallery();
     $photo->setEntity($this->getRequestParameter('entity'));
     $photo->setEntityId($this->getRequestParameter('entity_id'));
     $photo->setName($file_name);
     $photo->setMimeType($type);
     $photo->setSize($file_info['size']);
     $photo->setSuffix($suffix);
     $photo->setTitle($this->getRequestParameter('title'));
     $photo->setDescription($this->getRequestParameter('description'));
     $photo->save();
     $scale = true;
     $options = array();
     if (strtolower($this->getRequestParameter('entity')) == 'project') {
         $scale = false;
         $options['method'] = 'shave';
     }
     //Operazioni per salvare il file in upload:
     $this->getRequest()->moveFile('file', sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     //Creazione della thumb
     $thumbnail = new sfThumbnail(25, 25, $scale, true, 100, null, $options);
     $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/thumbnails/tiny/' . $photo->getRealName(), 'image/png');
     $thumbnail = new sfThumbnail(50, 50, $scale, true, 100, null, $options);
     $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/thumbnails/small/' . $photo->getRealName(), 'image/png');
     $thumbnail = new sfThumbnail(100, 100, $scale, true, 100, null, $options);
     $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/thumbnails/medium/' . $photo->getRealName(), 'image/png');
     $thumbnail = new sfThumbnail(125, 125, $scale, true, 100, null, $options);
     $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/thumbnails/large/' . $photo->getRealName(), 'image/png');
     $thumbnail = new sfThumbnail(640, 640);
     $thumbnail->loadFile(sfConfig::get('sf_upload_dir') . '/photos/' . $photo->getRealName());
     $thumbnail->save(sfConfig::get('sf_upload_dir') . '/photos/standard/' . $photo->getRealName(), 'image/png');
     // Fai il redirect dal referrer (TODO: oppure chiuditi come ajax)
     return $this->redirect($referer);
 }
 /**
  * Resize an image using the sfThubmnail Plugin.
  *
  * @param string $originalImageName
  * @param integer $width
  * @param integer $height
  *
  * @return string (thumbnail's bitstream)
  */
 public static function resizeImage($originalImageName, $width = null, $height = null)
 {
     $mimeType = QubitDigitalObject::deriveMimeType($originalImageName);
     // Get thumbnail adapter
     if (!($adapter = self::getThumbnailAdapter())) {
         return false;
     }
     // Check that this file can be thumbnailed, or return false
     if (self::canThumbnailMimeType($mimeType) == false) {
         return false;
     }
     // Create a thumbnail
     try {
         $newImage = new sfThumbnail($width, $height, true, false, 75, $adapter, array('extract' => 1));
         $newImage->loadFile($originalImageName);
     } catch (Exception $e) {
         return false;
     }
     return $newImage->toString('image/jpeg');
 }
 public function executeUpload()
 {
     $currentDir = $this->dot2slash($this->getRequestParameter('current_dir'));
     $webAbsCurrentDir = '/' . $this->uploadDirName . '/' . $currentDir;
     $absCurrentDir = $this->uploadDir . '/' . $currentDir;
     $this->forward404Unless(is_dir($absCurrentDir));
     $filename = $this->sanitizeFile($this->getRequest()->getFileName('file'));
     $info['ext'] = substr($filename, strpos($filename, '.') - strlen($filename) + 1);
     if ($this->isImage($info['ext']) && $this->useThumbnails) {
         if (!is_dir($absCurrentDir . '/' . $this->thumbnailsDir)) {
             // If the thumbnails directory doesn't exist, create it now
             $old = umask(00);
             @mkdir($absCurrentDir . '/' . $this->thumbnailsDir, 0777, true);
             umask($old);
         }
         $thumbnail = new sfThumbnail(64, 64);
         $thumbnail->loadFile($this->getRequest()->getFilePath('file'));
         $thumbnail->save($absCurrentDir . '/' . $this->thumbnailsDir . '/' . $filename);
     }
     $this->getRequest()->moveFile('file', $absCurrentDir . '/' . $filename);
     $this->redirect('sfMediaLibrary/index?dir=' . $this->getRequestParameter('current_dir'));
 }
 /**
  * Return the path a a valid thumbnail.
  * 
  * @static
  * @param  $file_path
  * @param array $options
  * @return string
  */
 public static function getThumbnailPath($file_path, $options = array())
 {
     if (is_null($file_path) || trim($file_path) === '') {
         return;
     }
     $options['maxWidth'] = isset($options['maxWidth']) ? $options['maxWidth'] : 150;
     $options['maxHeight'] = isset($options['maxHeight']) ? $options['maxHeight'] : 150;
     $options['dir'] = isset($options['dir']) ? $options['dir'] : sfConfig::get('app_asset_thumbnail_dir', '/uploads/_thumbnail_cache');
     $options['scale'] = isset($options['scale']) ? $options['scale'] : true;
     $options['inflate'] = isset($options['inflate']) ? $options['inflate'] : false;
     $options['quality'] = isset($options['quality']) ? $options['quality'] : sfConfig::get('app_rt_asset_thumbnail_quality', '95');
     $options['targetMime'] = isset($options['targetMime']) ? $options['targetMime'] : null;
     $options['adapterClass'] = isset($options['adapterClass']) ? $options['adapterClass'] : null;
     $options['adapterOptions'] = isset($options['adapterOptions']) ? $options['adapterOptions'] : array();
     $full_thumbnail_dir = sfConfig::get('sf_web_dir') . $options['dir'];
     $size_store_dir = DIRECTORY_SEPARATOR . $options['maxWidth'] . 'x' . $options['maxHeight'];
     $sub_web_dir = str_replace(sfConfig::get('sf_web_dir'), '', $file_path);
     $target = $full_thumbnail_dir . $size_store_dir . $sub_web_dir;
     if (!is_dir(dirname($target))) {
         mkdir(dirname($target), 0777, true);
     }
     if (!file_exists($target)) {
         // Process the thumbnail.
         $thumbnail = new sfThumbnail($options['maxWidth'], $options['maxHeight'], $options['scale'], $options['inflate'], $options['quality'], $options['adapterClass'], $options['adapterOptions']);
         $thumbnail->loadFile($file_path);
         $thumbnail->save($target, $options['targetMime']);
     }
     $cdn_tag = self::getCdnTagFilename();
     $cdn = '';
     if (file_exists($cdn_tag) && sfConfig::has('app_rt_cdn_host')) {
         if (filectime($cdn_tag) > filectime($target)) {
             $cdn = sfConfig::get('app_rt_cdn_host');
         }
     }
     return $cdn . $options['dir'] . $size_store_dir . $sub_web_dir;
 }
示例#25
0
 public function executeEdit()
 {
     $user = UserPeer::getByUsername($this->getRequestParameter('username'));
     // make sure it's a valid user, and that we're editing our own profile
     if (!$user instanceof User) {
         $this->error = 'No such user exists.';
         $this->setTemplate('_error');
         return sfView::SUCCESS;
     } else {
         if (!$this->getUser()->getRaykuUser()->equals($user)) {
             $this->error = 'You do not have permission to edit this user\'s profile.';
             $this->setTemplate('_error');
             return sfView::SUCCESS;
         }
     }
     // if form is submitted, persist the data
     if (sfWebRequest::POST === $this->getRequest()->getMethod()) {
         $_username = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?\$/i", "\$1", $this->getRequestParameter('_username'));
         $user->setName($this->getRequestParameter('realname'));
         $user->setUsername($_username);
         $user->setEmail($this->getRequestParameter('email'));
         $user->setGender($this->getRequestParameter('user[gender]'));
         $user->setHometown($this->getRequestParameter('hometown'));
         $user->setHomePhone($this->getRequestParameter('home_phone'));
         $user->setMobilePhone($this->getRequestParameter('mobile_phone'));
         $birthdate = RaykuCommon::dateArrayToString($this->getRequestParameter('birthdate'));
         $user->setBirthdate($birthdate);
         $user->setAddress($this->getRequestParameter('address'));
         $user->setRelationshipStatus($this->getRequestParameter('user[relationshipstatuse]'));
         // if the password is set
         if ('' !== $this->getRequestParameter('password1')) {
             $user->setPassword($this->getRequestParameter('password1'));
         }
         // set the 'show xxx' params..
         $user->setShowEmail($this->getRequestParameter('show_email', 0));
         $user->setShowGender($this->getRequestParameter('show_gender', 0));
         $user->setShowHometown($this->getRequestParameter('show_hometown', 0));
         $user->setShowHomePhone($this->getRequestParameter('show_home_phone', 0));
         $user->setShowMobilePhone($this->getRequestParameter('show_mobile_phone', 0));
         $user->setShowBirthdate($this->getRequestParameter('show_birthdate', 0));
         $user->setShowAddress($this->getRequestParameter('show_address', 0));
         $user->setShowRelationshipStatus($this->getRequestParameter('show_relationship_status', 0));
         $user->save();
         if (!empty($_FILES['file']['name'])) {
             $connection = RaykuCommon::getDatabaseConnection();
             $user = $this->getUser()->getRaykuUser();
             $fileName = $_FILES['file']['name'];
             $created_at = date("Y-m-d H:i:s");
             $contentType = '';
             $ext = substr($fileName, strrpos($fileName, '.') + 1);
             switch (strtolower($ext)) {
                 case 'jpeg':
                     $contentType = 'jpeg';
                     break;
                 case 'jpg':
                     $contentType = 'jpeg';
                     break;
                 case 'png':
                     $contentType = 'png';
                     break;
                 case 'gif':
                     $contentType = 'gif';
                     break;
                 case 'pjpeg':
                     $contentType = 'pjpeg';
                     break;
             }
             $checkcontentType = array('1' => 'jpeg', '2' => 'png', '3' => 'gif', '4' => 'pjpeg');
             // move to uploads
             $uploadDir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'profile';
             if (in_array($contentType, $checkcontentType)) {
                 $query = mysql_query("insert into user_profile(`user_id`, `file_name`,  `created_at`) VALUES (" . $user->getId() . ", '" . $fileName . "', '" . $created_at . "')", $connection) or die(mysql_error());
             }
             if ($query) {
                 $filename = mysql_insert_id();
                 $_query = mysql_query("select * from user_profile where user_id=" . $user->getId() . " and id != " . $filename . "", $connection);
                 if (mysql_num_rows($_query)) {
                     $_row = mysql_fetch_assoc($_query);
                     mysql_query("delete from user_profile where user_id=" . $user->getId() . " and id = " . $_row['id'] . " ", $connection);
                     $remove = $uploadDir . DIRECTORY_SEPARATOR . $_row['id'];
                     $remove = $uploadDir . DIRECTORY_SEPARATOR . $_row['id'] . "thumb2";
                     unlink($remove);
                 }
                 if (!file_exists($uploadDir)) {
                     mkdir($uploadDir, 0700, true);
                 }
                 $target = $uploadDir . DIRECTORY_SEPARATOR . $filename;
                 $successfullyMoved = move_uploaded_file($_FILES['file']['tmp_name'], $target);
                 if ($successfullyMoved) {
                     RaykuCommon::writeAvatarImage($target, $user->getId());
                 }
                 // create thumb
                 $thumb = new sfThumbnail(sfConfig::get('app_gallery_thumbnail2_max_width'), sfConfig::get('app_gallery_thumbnail2_max_height'));
                 $thumb->loadFile($target);
                 $thumb->save($target . 'thumb2');
             }
         }
         $this->redirect('/dashboard');
     }
     // passing to view
     $this->user = $user;
 }
示例#26
0
 public function executeCreate(sfWebRequest $request)
 {
     sfApplicationConfiguration::getActive()->loadHelpers(array('Parse', 'Text', 'Tag', 'I18N', 'Url'));
     $this->forward404Unless($request->isMethod('post'));
     $user = $this->getUser()->getGuardUser();
     try {
         $text = trim($this->getRequestParameter('text'));
         $blogs = array();
         $pictures = array();
         $moodNo = 0;
         $doWork = false;
         $useMoodNo = false;
         do {
             $doWork = false;
             if (substr($text, 0, 2) == ":D") {
                 $moodNo = 1;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 2) == ":(") {
                 $moodNo = -1;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 2) == ":)") {
                 $moodNo = 0;
                 $text = trim(substr($text, 2));
                 $doWork = true;
                 $useMoodNo = true;
             }
             if (substr($text, 0, 1) == "#" || substr($text, 0, 1) == "*") {
                 $tags = split("[,;:|\n]", $text);
                 $blog = Blog::getOrCreateByTag(trim(substr($tags[0], 1)), $user);
                 if ($blog) {
                     $text = trim(substr($text, strlen($tags[0]) + 1));
                     $blogs[] = $blog;
                     $doWork = true;
                 }
             }
         } while ($doWork);
         $post = new Post();
         $post->setTextOriginal($text);
         $post->setText(parsetext($text));
         if ($useMoodNo) {
             $post->setMood($moodNo);
         } else {
             $post->setMoodName($this->getRequestParameter('mood'));
         }
         $post->setUser($user);
         if ($this->getRequestParameter('picture_url')) {
             $filename = jrFileUploader::UploadRemote($request->getParameter('picture_url'));
             $pictures[] = array('value' => '/uploads/' . $filename, 'origin' => $request->getParameter('picture_url'));
         }
         $uploaded_file = $request->getFiles('picture');
         if ($uploaded_file['tmp_name']) {
             $pathinfo = pathinfo($uploaded_file['name']);
             $name = time() . rand(1, 999999);
             $extension = $pathinfo["extension"] ? $pathinfo["extension"] : "jpg";
             $filename = $name . "." . $extension;
             $origin = $name . "_origin." . $extension;
             $thumbnail = new sfThumbnail(811, 0, true, false, 100, sfConfig::get('app_sfThumbnailPlugin_adapter', 'sfGDAdapter'));
             $thumbnail->loadFile($uploaded_file['tmp_name']);
             $thumbnail->save(sfConfig::get('sf_upload_dir') . '/' . $filename);
             move_uploaded_file($uploaded_file['tmp_name'], sfConfig::get('sf_upload_dir') . '/' . $origin);
             $pictures[] = array('value' => '/uploads/' . $filename, 'origin' => '/uploads/' . $origin);
         }
         foreach ($blogs as $blog) {
             $post->getBlogs()->add($blog);
         }
         foreach ($pictures as $pic) {
             $postAttr = new PostAttribute();
             $postAttr->setType('picture');
             $postAttr->setValue($pic['value']);
             $postAttr->setOrigin($pic['origin']);
             $post->getAttributes()->add($postAttr);
         }
         $post->save();
         /*if(!$this->getRequestParameter('noajax')) {
               if($this->getRequestParameter('mypage'))
                   $post_list = $user->getLine();
               else
                   $post_list = Post::getNewLine();
               return $this->renderPartial('post/postList', array('posts' => $post_list));
           }
           else
               $this->redirect(url_for('post/new'));*/
         if ($this->getRequestParameter('mypage')) {
             $this->redirect(url_for('post/user'));
         } else {
             $this->redirect(url_for('post/new'));
         }
     } catch (Exception $e) {
         echo $e;
         echo "Возникла ошибка при создании поста.<br/>\n";
         if ($this->getRequestParameter('text')) {
             echo "Текст поста был такой:<br/>\n";
             echo "<hr/>" . nl2br(htmlentities(trim($this->getRequestParameter('text')))) . "<hr/><br/>\n";
         }
         if ($this->getRequestParameter('noajax')) {
             echo "<a href='" . $this->getRequest()->getReferer() . "'>назад</a>";
         }
         die;
     }
 }
    $t->diag('creates inflated thumbnail');
    $thmb = new sfThumbnail(200, 200, false, true, 75, $adapter, array());
    $thmb->loadFile($data['image/gif']);
    $thmb->save($result . '.gif');
    checkResult($t, 200, 200, 'image/gif');
    $t->diag('creates image from string');
    $thmb = new sfThumbnail(200, 200, false, true, 75, $adapter, array());
    $blob = file_get_contents($data['blob']);
    $thmb->loadData($blob, 'image/jpeg');
    $thmb->save($result . '.jpg', 'image/jpeg');
    checkResult($t, 200, 200, 'image/jpeg');
    // imagemagick-specific tests
    if ($adapter == 'sfImageMagickAdapter') {
        $t = new my_lime_test($tests_imagemagick, new lime_output_color());
        $t->diag('creates thumbnail from pdf', $adapter);
        $thmb = new sfThumbnail(150, 150, true, true, 75, $adapter, array('extract' => 1));
        $thmb->loadFile($data['document/pdf']);
        $thmb->save($result . '.jpg');
        checkResult($t, 150, 116, 'image/jpeg');
    }
}
function checkResult($t, $width, $height, $mime)
{
    global $mimeMap;
    $result = getResultPath();
    $result .= '.' . $mimeMap[$mime];
    // check generated thumbnail for expected results
    // use getimagesize() when possible, otherwise use 'identify'
    $imgData = @getimagesize($result);
    if ($imgData) {
        $res_width = $imgData[0];
 /**
  * Generate a thumbnail of a given type.
  * 
  * @param string $thumb_type thumbnail type
  * @param array $thumb_options thumbnail options (width, height and other as set in configuration).
  * @return bool true = success, false = failure.
  */
 protected function generateThumbnail($thumb_type, $thumb_options)
 {
     if (!class_exists('sfThumbnail') || !file_exists($this->source)) {
         return false;
     }
     $width = isset($thumb_options['width']) ? $thumb_options['width'] : null;
     $height = isset($thumb_options['height']) ? $thumb_options['height'] : null;
     $options = array('extract' => 1);
     $scale = true;
     if (isset($thumb_options['shave']) && $thumb_options['shave'] == true) {
         $options = array_merge(array('method' => 'shave_all'), $options);
         $scale = false;
     }
     $thumbnail = new sfThumbnail($width, $height, $scale, true, 85, sfConfig::get('app_lyMediaManager_use_ImageMagick', false) ? 'sfImageMagickAdapter' : 'sfGDAdapter', $options);
     $thumbnail->loadFile($this->source);
     $thumbnail->save($this->getThumbnailPath($thumb_type), $this->mime_type);
     return true;
 }
示例#29
-1
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $files = $request->getFiles($form->getName());
     $form->bind($request->getParameter($form->getName()), $files);
     if ($form->isValid()) {
         $profile = $form->save();
         $profile->getUser()->first_name = $form->getValue('first_name');
         $profile->getUser()->last_name = $form->getValue('last_name');
         $profile->getUser()->save();
         if ($files['userpic']['name']) {
             $userpic = new sfThumbnail(48, 48, false);
             $userpic->loadFile($files['userpic']['tmp_name']);
             $name = md5($profile->id . 'userpic f**k yea') . '.png';
             $userpic->save(sfConfig::get('sf_user_pic_dir') . $name, 'image/png');
             $profile->userpic = $name;
             $profile->save();
         }
         $this->redirect('profile/show?id=' . $profile->getId());
     } else {
         //            foreach ($form->getFormFieldSchema() as $name => $formField) {
         //                if ($formField->getError() != "") {
         //                    echo "ActionClassName::methodName( ): Field Error for :" . $name . " : " . $formField->getError();
         //                }
         //            }
     }
 }
示例#30
-2
 public static function createThumbnail($object, $module, $template, $width, $height, $media_name, $media_artist, $user)
 {
     $thumbnail_name = '';
     $settings = Doctrine_Core::getTable('Settings')->findOneByUserId($user);
     //preparing the name of thumbnail. Special case Music has artist also in the thumbnail name
     if ($media_artist != NULL) {
         $thumbnail_name .= Util::unformatName($media_artist) . ' - ' . Util::unformatName($media_name);
     } else {
         $thumbnail_name .= Util::unformatName($media_name);
     }
     //then create the thumbnail object for index image
     $thumbnail = new sfThumbnail($width, $height, false, false, 100);
     //Loading file. Special case: an album has its cover inside the album folder
     if ($module == 'music') {
         $filepath = Util::makePath(array($settings[$module . '_root'], Util::unformatName($object['title']), $thumbnail_name . '.jpg'));
     } else {
         if ($module == 'movies') {
             $filepath = Util::makePath(array($settings[$module . '_root'], 'Covers', $thumbnail_name . '.jpg'));
         } else {
             if ($module == 'photoalbums') {
                 $filepath = Util::makePath(array($settings[$module . '_root'], Util::unformatName('[' . $object['date'] . '] ' . $object['title']), $settings['covers'] . '.jpg'));
             } else {
                 $filepath = Util::makePath(array($settings[$module . '_root'], Util::unformatName($object['title']), $settings['covers'] . '.jpg'));
             }
         }
     }
     if (file_exists($filepath)) {
         $thumbnail->loadFile($filepath);
         //Creating thumbnail image
         $image_rel_path = Util::makePath(array($settings[$module . '_thumb_rel_' . $template], $thumbnail_name . '.jpg'));
         $image_abs_path = Util::makePath(array($settings[$module . '_thumb_abs_' . $template], $thumbnail_name . '.jpg'));
         $thumbnail->save($image_abs_path, 'image/jpeg');
         chmod($image_abs_path, 0777);
         $object['cover_' . $template] = utf8_encode(Util::changePathSeparators($image_rel_path));
         $object->save();
         return 0;
     } else {
         return 1;
     }
 }