示例#1
0
 public function save($conn = null)
 {
     parent::save();
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMAGE;
     $OC = $this->getObject();
     if ($OC instanceof Cicles) {
         $I = $OC->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $OC->getCicleid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OC->setImatge($nom)->save();
         }
         $P = $OC->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OC->getCicleid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($P != $nom) {
                 unlink($BASE . $P);
             }
             $OC->setPdf($nom)->save();
         }
     }
 }
示例#2
0
 public function save($conn = null)
 {
     parent::save();
     $BASE = $this->URL_IMAGE;
     $ON = $this->getObject();
     if ($ON instanceof Noticies) {
         $I = $ON->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $ON->getIdnoticia() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $ON->setImatge($nom)->save();
         }
         $P = $ON->getAdjunt();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $ON->getIdnoticia() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $ON->setAdjunt($nom)->save();
         }
     }
 }
 protected function createMask(sfImage $image, $w, $h)
 {
     // Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
     $mask = $image->getAdapter()->getTransparentImage($w, $h);
     // Set the masking colours
     if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
         $mask_black = imagecolorallocate($mask, 0, 0, 0);
     } else {
         $mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
     }
     // Cannot use white as transparent mask if color is set to white
     if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
         $mask_transparent = imagecolorallocate($mask, 255, 0, 0);
     } else {
         $mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
         $mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
     }
     imagecolortransparent($mask, $mask_transparent);
     imagefill($mask, 0, 0, $mask_black);
     // Draw the rounded rectangle for the mask
     $this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
     $mask_image = clone $image;
     $mask_image->getAdapter()->setHolder($mask);
     return $mask_image;
 }
示例#4
0
 public function updateObject($values = null)
 {
     $object = parent::updateObject($values);
     if ($av = $object->getAvatar('raw')) {
         $tmp_name = sfConfig::get('sf_upload_dir') . '/avatars/' . $av;
         if (!file_exists($tmp_name)) {
             return $object;
         }
         // Génération miniature 50x50
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(50, 50, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/50x50/' . $av);
         // Génération miniature 32x32
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(32, 32, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/32x32/' . $av);
         // Génération miniature 16x16
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(16, 16, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/16x16/' . $av);
         // On supprime le fichier original
         unlink($tmp_name);
     }
     return $object;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $resourcex = imagesx($resource);
     $resourcey = imagesy($resource);
     for ($x = 0; $x < $resourcex; ++$x) {
         for ($y = 0; $y < $resourcey; ++$y) {
             $distx = rand(-$this->scatter_factor, $this->scatter_factor);
             $disty = rand(-$this->scatter_factor, $this->scatter_factor);
             // keep inside the image boundaries
             if ($x + $distx >= $resourcex) {
                 continue;
             }
             if ($x + $distx < 0) {
                 continue;
             }
             if ($y + $disty >= $resourcey) {
                 continue;
             }
             if ($y + $disty < 0) {
                 continue;
             }
             $oldcol = imagecolorat($resource, $x, $y);
             $newcol = imagecolorat($resource, $x + $distx, $y + $disty);
             imagesetpixel($resource, $x, $y, $newcol);
             imagesetpixel($resource, $x + $distx, $y + $disty, $oldcol);
         }
     }
     return $image;
 }
 public function save($conn = null)
 {
     parent::save();
     $OR = $this->getObject();
     if (!is_null($this['Categories']->getValue())) {
         $OR->setCategories(implode('@', $this['Categories']->getValue()));
     }
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMATGE;
     if ($OR instanceof Activitats) {
         $I = $OR->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OR->getActivitatid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OR->setImatge($nom);
         }
         $P = $OR->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OR->getActivitatid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $OR->setPdf($nom);
         }
     }
     $OR->save();
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param integer
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     // Check we have a valid image resource
     $resource = $image->getAdapter()->getHolder();
     $resource->flopImage();
     return $image;
 }
示例#8
0
function image_cache_tag($route, $format, $path, $image, $alt = null)
{
    $_formats = sfConfig::get('imagecache_formats');
    $_format = $_formats[$format];
    if (!isset($_format)) {
        throw new RuntimeException('Format not found');
    }
    $real_file_path = sfConfig::get('sf_upload_dir') . '/' . $path . '/' . $image;
    if (file_exists($real_file_path)) {
        $cache_file_path = sfConfig::get('sf_upload_dir') . '/cache/' . $format . '/' . $path . '/' . $image;
        $is_cached_file = file_exists($cache_file_path);
        $options = array('path' => $format . '/' . $path . '/' . $image);
        $url = urldecode(url_for($route, $options));
        if ($is_cached_file) {
            $cached_image = new sfImage($cache_file_path);
            $width = $cached_image->getWidth();
            $height = $cached_image->getHeight();
            return image_tag($url, array('size' => $width . 'x' . $height, 'alt' => $alt));
        } else {
            return image_tag($url, array('alt' => $alt));
        }
    } else {
        return '';
    }
}
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 public function execute(sfImage $image)
 {
     // Check we have a valid image holder
     if (false === $image->getAdapter()->hasHolder()) {
         throw new sfImageTransformException(sprintf('Cannot perform transform: %s invalid image resource', get_class($this)));
     }
     return $this->transform($image);
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = imagesx($resource);
     $y = imagesy($resource);
     $image->resize(round($x * $this->scale), round($y * $this->scale));
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = $resource->getImageWidth();
     $y = $resource->getImageHeight();
     $image->resize(round($x * $this->scale), round($y * $this->scale));
     return $image;
 }
示例#12
0
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     if ($this->get('sticky') == 'no') {
         $this->set('sticky', 1000);
     }
     parent::save($conn);
     $config = sfConfig::get('app_sfDoctrineJCroppablePlugin_models');
     $dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $config['Events']['directory'];
     $image = $this->getImageSrc('mugshot', 'original');
     if ($this->getMugshot() != '') {
         $arr_filename = explode('.', $this->getMugshot());
         $filename = $arr_filename[0] . '_original.' . $arr_filename[1];
         $file = $dir . DIRECTORY_SEPARATOR . $filename;
         if (is_file($file)) {
             $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141));
             $size = getimagesize($file);
             $img = new sfImage($file, $size['mime']);
             foreach ($dims as $dim) {
                 $img->resize($dim['w'], $dim['h']);
                 $img->setQuality(90);
                 $img->saveAs($dir . '/' . $arr_filename[0] . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
             }
         }
     }
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     if (function_exists('imagefilter')) {
         imagefilter($resource, IMG_FILTER_NEGATE);
     } else {
         throw new sfImageTransformException(sprintf('Cannot perform transform, GD does not support imagefilter '));
     }
     return $image;
 }
示例#14
0
 public function save($conn = null)
 {
     $OPromocions = $this->getObject();
     PromocionsPeer::gestionaOrdre($this->getValue('Ordre'), $OPromocions->getOrdre(), $this->getOption('IDS'));
     parent::save();
     $nom = $OPromocions->getExtensio();
     if (!empty($nom)) {
         $img = new sfImage($this->URL . $nom, 'image/jpg');
         $img->resize(171, 63)->saveAs($this->URL . $nom);
     }
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     // Set the defined color as transparent
     if ($this->color !== '') {
         $color = $image->getAdapter()->getColorByHex($resource, $this->color);
     } else {
         $color = imagecolorat($resource, 0, 0);
     }
     imagecolortransparent($resource, $color);
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $resourcex = imagesx($resource);
     $resourcey = imagesy($resource);
     for ($x = 0; $x < $resourcex; $x += $this->block_size) {
         for ($y = 0; $y < $resourcey; $y += $this->block_size) {
             $rgb = imagecolorat($resource, $x, $y);
             imagefilledrectangle($resource, $x, $y, $x + $this->block_size - 1, $y + $this->block_size - 1, $rgb);
         }
     }
     return $image;
 }
示例#17
0
文件: Page.class.php 项目: Gula/magic
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     parent::save($conn);
     // generamos thumbnails
     $file = sfConfig::get('sf_upload_dir') . '/pictures/' . $this->getPicture();
     if (is_file($file)) {
         $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141), array('w' => 60, 'h' => 60));
         $size = getimagesize($file);
         $img = new sfImage($file, $size['mime']);
         if (!is_dir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'))) {
             mkdir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'), 0777);
         }
         foreach ($dims as $dim) {
             $img->thumbnail($dim['w'], $dim['h']);
             $img->setQuality(90);
             $img->saveAs(sfConfig::get('sf_upload_dir') . '/' . $this->get('id') . '/img_' . $this->get('id') . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
         }
     }
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     // No need to do anything
     if ($this->angle == 0) {
         return $image;
     }
     $resource = $image->getAdapter()->getHolder();
     // By default use the background of the top left corner
     if ($this->background === '') {
         $this->background = $resource->getImagePixelColor(0, 0);
     }
     $resource->rotateImage($this->background, $this->angle);
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     // By default use the background of the top left corner
     if (is_null($this->background)) {
         $this->background = $resource->getImagePixelColor(0, 0);
         $background = $this->background;
     } else {
         $background = new ImagickPixel();
         $background->setColor($this->background);
     }
     $resource->setBackgroundColor($background);
     $resource->trimImage($this->fuzz);
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param integer
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = imagesx($resource);
     $y = imagesy($resource);
     $dest_resource = $image->getAdapter()->getTransparentImage($x, $y);
     for ($h = 0; $h < $y; $h++) {
         imagecopy($dest_resource, $resource, 0, $h, 0, $y - $h - 1, $x, 1);
     }
     // Tidy up
     imagedestroy($resource);
     // Replace old image with flipped version
     $image->getAdapter()->setHolder($dest_resource);
     return $image;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @access protected
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $resourcex = imagesx($resource);
     $resourcey = imagesy($resource);
     for ($x = 0; $x < $resourcex; ++$x) {
         for ($y = 0; $y < $resourcey; ++$y) {
             $newr = 0;
             $newg = 0;
             $newb = 0;
             $colours = array();
             $thiscol = imagecolorat($resource, $x, $y);
             for ($k = $x - $this->blur_pixels; $k <= $x + $this->blur_pixels; ++$k) {
                 for ($l = $y - $this->blur_pixels; $l <= $y + $this->blur_pixels; ++$l) {
                     if ($k < 0) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($k >= $resourcex) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($l < 0) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     if ($l >= $resourcey) {
                         $colours[] = $thiscol;
                         continue;
                     }
                     $colours[] = imagecolorat($resource, $k, $l);
                 }
             }
             foreach ($colours as $colour) {
                 $newr += $colour >> 16 & 0xff;
                 $newg += $colour >> 8 & 0xff;
                 $newb += $colour & 0xff;
             }
             $numelements = count($colours);
             $newr /= $numelements;
             $newg /= $numelements;
             $newb /= $numelements;
             $newcol = imagecolorallocate($resource, $newr, $newg, $newb);
             imagesetpixel($resource, $x, $y, $newcol);
         }
     }
     return $image;
 }
示例#22
0
 /**
  * Cache the image based on the size set in thumbnails.yml
  */
 public function cache()
 {
     $cache_dir = pathinfo($this->cached_path, PATHINFO_DIRNAME);
     //create cache dir if it doesn't exist
     if (!file_exists($cache_dir)) {
         mkdir($cache_dir, 0777, true);
     }
     $size = zsThumbConfigHandler::getSize($this->size);
     //do image transformations
     $new_image = new sfImage($this->orig_path);
     $new_image->thumbnail($size['width'], $size['height'], array_key_exists('method', $size) ? $size['method'] : 'fit');
     if (array_key_exists('quality', $size)) {
         $new_image->setQuality($size['quality']);
     }
     $new_image->saveAs($this->cached_path);
 }
 protected function saveFile($field, $filename = null, sfValidatedFile $file = null)
 {
     $file_saved = parent::saveFile($field, $filename = null, $file);
     // generate images ?
     if (sfConfig::get('app_sfMooDooGalleryPlugin_generate_images')) {
         $sizes = sfConfig::get('app_sfMooDooGalleryPlugin_image_size');
         $name = explode('.', $file_saved);
         foreach ($sizes as $size) {
             $image_name = sfConfig::get('app_sfMooDooGalleryPlugin_images_dir') . DIRECTORY_SEPARATOR . $name[0] . '_' . $size['width'] . 'x' . $size['height'] . $file->getExtension();
             $img = new sfImage($file, $file->getType());
             $img->resize($size['width'], $size['height']);
             $img->saveAs($image_name);
         }
     }
     return $file_saved;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param integer
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = imagesx($resource);
     $y = imagesy($resource);
     imagealphablending($resource, true);
     $dest_resource = $image->getAdapter()->getTransparentImage($x, $y);
     imagealphablending($dest_resource, true);
     for ($w = 0; $w < $x; $w++) {
         imagecopy($dest_resource, $resource, $w, 0, $x - $w - 1, 0, 1, $y);
     }
     // Tidy up
     imagedestroy($resource);
     // Replace old image with flipped version
     $image->getAdapter()->setHolder($dest_resource);
     return $image;
 }
 /**
  * Apply the opacity transformation to the sfImage object
  * 
  * @param sfImage
  * 
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $new_img = $image->getAdapter()->getTransparentImage($image->getWidth(), $image->getHeight());
     imagealphablending($new_img, false);
     imagesavealpha($new_img, true);
     $opacity = (int) round(127 - 127 / 100 * $this->getOpacity());
     // imagesavealpha($new_img, true);
     $width = $image->getWidth();
     $height = $image->getHeight();
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $rgb = imagecolorat($image->getAdapter()->getHolder(), $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $alpha = ($rgb & 0x7f000000) >> 24;
             $new_opacity = $alpha + (127 - $alpha) / 100 * $this->getOpacity();
             $colors[$alpha] = $new_opacity;
             $color = imagecolorallocatealpha($new_img, $r, $g, $b, $new_opacity);
             imagesetpixel($new_img, $x, $y, $color);
         }
     }
     $image->getAdapter()->setHolder($new_img);
     return $image;
 }
 /**
  * Generates a thumbnail.
  *
  * The generation is actually done by the sfImageTransformPlugin. This method only collects the
  * options configured in the thumbnailing.yml and uses them to call sfImageTransformPlugins transformations.
  * Additionally the generated thumbnail can be cached.
  *
  * @param  string  $uri     Image source URI (sfImageSource://...)
  * @param  array   $options Thumbnail parameters taken from the thumbnail URL referencing a format and id
  * @return sfImage
  */
 public function generate($uri, $format)
 {
     if (!array_key_exists($format, $this->options['formats'])) {
         throw new sfImageTransformExtraPluginConfigurationException('Unknown format "' . $format . '" in your thumbnailing.yml!');
     }
     $sourceImage = new sfImage($uri);
     $settings = $this->options['formats'][$format];
     if (array_key_exists('mime_type', $settings)) {
         $sourceImage->setMIMEType($settings['mime_type']);
     }
     if (is_array($settings['transformations'])) {
         foreach ($settings['transformations'] as $transformation) {
             $this->transform($sourceImage, $transformation);
         }
     }
     $sourceImage->setQuality($settings['quality']);
     return $sourceImage;
 }
 public function storeScreenshot()
 {
     $path = sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_screenshots_path') . '/' . $this->getPluginId() . '/' . $this->getId();
     ForgeToolkit::createRecursiveDirectory($path . '/thumbs/');
     $filename = $this->getFilename();
     try {
         $tmp = tempnam(sys_get_temp_dir(), uniqid($this->getUrl() . time()));
         @copy($this->getUrl(), $tmp);
         if (@file_get_contents($tmp)) {
             $image = new sfImage($tmp);
             $image->saveAs($path . '/' . $filename);
             $image->thumbnail(sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'width'), sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'height'), 'center');
             $image->saveAs($path . '/thumbs/' . $filename, 'image/png');
         }
     } catch (sfImageTransformException $e) {
         $this->delete();
     }
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $resourcex = imagesx($resource);
     $resourcey = imagesy($resource);
     for ($x = 0; $x < $resourcex; ++$x) {
         for ($y = 0; $y < $resourcey; ++$y) {
             $rgb = imagecolorat($resource, $x, $y);
             $red = $rgb >> 16 & 0xff;
             $green = $rgb >> 8 & 0xff;
             $blue = $rgb & 0xff;
             $red = (int) (($red + $green + $blue) / 3);
             $modifier = rand(-$this->density, $this->density);
             $red += $modifier;
             $green += $modifier;
             $blue += $modifier;
             // Max value is 255
             // Min value is 0
             if ($red > 255) {
                 $red = 255;
             }
             if ($green > 255) {
                 $green = 255;
             }
             if ($blue > 255) {
                 $blue = 255;
             }
             if ($red < 0) {
                 $red = 0;
             }
             if ($green < 0) {
                 $green = 0;
             }
             if ($blue < 0) {
                 $blue = 0;
             }
             $newcol = imagecolorallocate($resource, $red, $green, $blue);
             imagesetpixel($resource, $x, $y, $newcol);
         }
     }
     return $image;
 }
示例#29
0
 public function save($conn = null)
 {
     parent::save();
     $OS = $this->getObject();
     $BASE = $this->BASE . $this->WEB_IMATGE;
     if ($OS instanceof Sites) {
         $I = $OS->getLogourl();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OS->getSiteId() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OS->setLogourl($nom);
         }
     }
     $OS->save();
 }
示例#30
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $file = $this->form->getValue('image');
         $image = $this->form->getObject();
         $notice = $image->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
         try {
             // Image
             $filename = 'app_' . sha1($file->getOriginalName() . rand(1, 100));
             $extension = str_replace('.', '', $file->getOriginalExtension());
             $path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $filename . '.' . $extension;
             $file->save($path);
             // Thumb
             $img = new sfImage($path, 'image/jpg');
             $img->thumbnail(150, 150);
             $img->saveAs(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $filename . '_thumb' . '.' . $extension);
             // Save
             $image->path = $filename . '.' . $extension;
             $image->type = $extension;
             $image->name = $request->getPostParameter('picture[name]');
             $image->description = $request->getPostParameter('picture[description]');
             $image->apartment_id = $request->getPostParameter('picture[apartment_id]');
             $image->save();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         // $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $picture)));
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }