Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Controller/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function cropImageAction(Request $request
$tarH = (int) round($config['cropConfig']['minHeight']);

$forceResize = $config['cropConfig']['forceResize'];
$default_jpeg_quality = $this->container->getParameter('comur_image.jpeg_quality');
// $disableCrop = $config['cropConfig']['disableCrop'];

$uploadUrl = urldecode($config['uploadConfig']['uploadUrl']);
Expand Down Expand Up @@ -154,7 +155,8 @@ public function cropImageAction(Request $request

}

$this->resizeCropImage($destSrc,$src,0,0,$x,$y,$destW,$destH,$w,$h);
$jpegQuality = isset($config['cropConfig']['jpeg_quality']) ? $config['cropConfig']['jpeg_quality'] : $defaultJpegQuality;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

i think it should be $default_jpeg_quality and not $defaultJpegQuality.

$this->resizeCropImage($destSrc,$src,0,0,$x,$y,$destW,$destH,$w,$h,$jpegQuality);

$galleryThumbOk = false;
$isGallery = isset($config['uploadConfig']['isGallery']) ? $config['uploadConfig']['isGallery'] : false;
Expand Down Expand Up @@ -196,7 +198,8 @@ public function cropImageAction(Request $request

$thumbName = $maxW.'x'.$maxH.'-'.$imageName;
$thumbSrc = $thumbDir . $thumbName;
$this->resizeCropImage($thumbSrc, $destSrc, 0, 0, 0, 0, $w, $h, $destW, $destH);
$thumbJpegQuality = isset($thumb['jpeg_quality']) ? $thumb['jpeg_quality'] : $jpegQuality;
$this->resizeCropImage($thumbSrc, $destSrc, 0, 0, 0, 0, $w, $h, $destW, $destH, $thumbJpegQuality);
if(isset($thumb['useAsFieldImage']) && $thumb['useAsFieldImage']){
$previewSrc = '/'.$config['uploadConfig']['webDir'] . '/' . $this->container->getParameter('comur_image.cropped_image_dir') . '/'. $this->container->getParameter('comur_image.thumbs_dir'). '/' . $thumbName;
}
Expand Down Expand Up @@ -289,7 +292,7 @@ public function getLibraryImagesAction(Request $request){
/**
* Crops or resizes image and writes it on disk
*/
private function resizeCropImage($destSrc, $imgSrc, $destX, $destY, $srcX, $srcY, $destW, $destH, $srcW, $srcH)
private function resizeCropImage($destSrc, $imgSrc, $destX, $destY, $srcX, $srcY, $destW, $destH, $srcW, $srcH, $jpeg_quality = 90)
{
$type = strtolower(pathinfo($imgSrc, PATHINFO_EXTENSION));

Expand All @@ -298,7 +301,7 @@ private function resizeCropImage($destSrc, $imgSrc, $destX, $destY, $srcX, $srcY
case 'jpeg':
$srcFunc = 'imagecreatefromjpeg';
$writeFunc = 'imagejpeg';
$imageQuality = 100;
$imageQuality = $jpeg_quality;
break;
case 'gif':
$srcFunc = 'imagecreatefromgif';
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/ComurImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('comur_image.gallery_thumb_size', $config['config']['gallery_thumb_size']);
$container->setParameter('comur_image.web_dirname', $config['config']['web_dirname']);
$container->setParameter('comur_image.translation_domain', $config['config']['translation_domain']);
$container->setParameter('comur_image.jpeg_quality', $config['config']['jpeg_quality']);
}
}
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function getConfigTreeBuilder()
->scalarNode('gallery_thumb_size')->defaultValue(150)->cannotBeEmpty()->end()
->scalarNode('web_dirname')->defaultValue('web')->cannotBeEmpty()->end()
->scalarNode('translation_domain')->defaultValue('ComurImageBundle')->cannotBeEmpty()->end()
->scalarNode('jpeg_quality')->defaultValue(90)->cannotBeEmpty()->end()
->end()
->end()
->end()
Expand Down
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Configuration
translation_domain: 'ComurImageBundle'
gallery_thumb_size: 150
gallery_dir: 'gallery'
jpeg_quality: 90

###cropped_image_dir###

Expand Down Expand Up @@ -165,6 +166,10 @@ That's the gallery directory name. The widget will store all gallery images in a

**For eg.** if you put 'uploads/images' as webDir when you add the widget, gallery images will be stored in 'uploads/images/*[gallery_dir]*'. This is added to make gallery use easier so you don't have to add new functions to your entities to get gallery dirs.

###jpeg_quality###

That's the quality of jpeg. It will be applied to all cropped images (and thumbs), if their aren't have own quality option.

#Usage#


Expand Down Expand Up @@ -262,6 +267,52 @@ To save original image path, you have to create another field and name it same a

I will put a demo soon…

Setting JPEG quality of cropped images
------------

If your field definition doesn't have specified value, then its param will be get from global option (from config.yml) or set to default value (`90`).

But you may set jpegQuality option for any field and even for any separate thumb:

public function buildForm(FormBuilderInterface $builder, array $options)
{
// get your entity related with your form type
$myEntity = $builder->getForm()->getData();
...
->add('image', 'comur_image', array(
'uploadConfig' => array(
'uploadRoute' => 'comur_api_upload', //optional
'uploadUrl' => $myEntity->getUploadRootDir(), // required
'webDir' => $myEntity->getUploadDir(), // required
'fileExt' => '*.jpg;*.gif;*.png;*.jpeg', //optional
'libraryDir' => null, //optional
'libraryRoute' => 'comur_api_image_library', //optional
'showLibrary' => true, //optional
'saveOriginal' => 'originalImage' //optional
),
'cropConfig' => array(
'minWidth' => 588,
'minHeight' => 300,
'aspectRatio' => true, //optional
'cropRoute' => 'comur_api_crop', //optional
'forceResize' => false, //optional
'jpegQuality' => 75, //optional, set quality for all thumbs of this field
'thumbs' => array( //optional
array(
'maxWidth' => 180,
'maxHeight' => 400,
'useAsFieldImage' => true //optional
),
array(
'maxWidth' => 180,
'maxHeight' => 400,
'jpegQuality' => 60 // override quality for this thumb
)
)
)
))


Gallery widget
------------

Expand Down