I'am trying to generate thumbnails with uploaded images in CakePHP.
I have worked with Rails and I used paperclip for that purpose, is there any way to do the same with CakePHP?
to be clear, I want to shrink the images keeping the ratio and then crop them in order to get them in the size I want.
If you have PHP available, you can try phpThumb, which does all that for you and much more. It can crop, zoom-crop, transform, blur, contrast...etc etc, and it auto-creates the thumbnails and keeps them in cache so it doesn't have to re-crop...etc each time the image is loaded.
It's also VERY simple to install and use, which is a big plus.
For CakePHP, you can just put the phpthumb folder in your webroot/ directory and use it just like normal.
Sounds like you might be looking for something like my Polyclip plugin. It's not feature-complete so I haven't documented it very well yet (I'll work on that as soon as I can), but it is in production and the core functionality that's in place seems to do what I need. Here's how I have it deployed with an Attraction model.
public $actsAs = array(
'Polyclip.attachable' => array(
'Image' => array(
'Thumbnails' => array(
'medium' => array( 'width' => 250, 'height' => 250, 'method' => 'resize_to_fit' ),
'square' => array( 'width' => 100, 'height' => 100, 'method' => 'resize_to_fill' ),
'sidebar' => array( 'width' => 290, 'height' => 100, 'method' => 'resize_to_fill' )
)
)
)
);
This attaches an image to the attraction with 3 thumbnails created automatically. As I said, it's not documented, but it's out there to fill the need you're looking to fill.
Related
I can't figure out how to enable custom page sizes with CakePDF and wkhtmltopdf. I have the following configuration code:
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
],
'orientation' => 'portrait',
'pageSize' => '', // this line
'download' => true
]);
I want to have 150x150mm pages. I already tried several things like passing an array [150,150] but also things like '150 150' or '150mm 150mm'. Is this even possible?
The CakePDF pageSize option maps to the page-size option of wkhtmltopdf, which takes QPrinter::PaperSize constant names, like for example A4, A5, B0, B1, Legal, Letter, etc., ie you cannot define a custom size using that option.
If you need a custom size, then you have to use the wkhtmltopdf specific page-width and page-height options, which both take millimeter values by default.
Quote from the wkhtmltopdf docs:
Page sizes:
The default page size of the rendered document is A4, but using this
--page-size option this can be changed to almost anything else, such as: A3,
Letter and Legal. For a full list of supported pages sizes please see
http://qt-project.org/doc/qt-4.8/qprinter.html#PaperSize-enum.
For a more fine grained control over the page size the --page-height and
--page-width options may be used
Configure::write('CakePdf', [
'engine' => [
'className' => 'CakePdf.WkHtmlToPdf',
'binary' => '/usr/local/bin/wkhtmltopdf',
'options' => [
'page-width' => 150,
'page-height' => 150
]
],
'orientation' => 'portrait',
'download' => true
]);
See also
wkhtmltopdf docs
Qt Documentation > QtGui > QPrinter > enum QPrinter::PaperSize
How to add more options in "Image manipulation" editor in typo3 FAL Image
Please find below Image for detail description
Createn an extension and install it. Create the file Configuration/TCA/Overrides/sys_file_reference.php. This is where you can add ratios to the cropping tool:
$GLOBALS['TCA']['sys_file_reference']['columns']['crop']['config'] = array(
'type' => 'imageManipulation',
'allowedExtensions' => 'jpg',
'ratios' => array(
'1.7777777777777777' => '16:9',
'1.3333333333333333' => '4:3',
'0.71428571428571' => '5:7',
'1' => '1:1',
'NaN' => 'Free',
),
);
I want an image on the right, text on the left floating around the image. The other way round works pretty good, there also is an example for that on the Recipies section in the documentation. However, I did not get this working with images floating on the right. What I tried:
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute'
)
);
or
addImage('myimage.png',
array(
'width'=>320,
'height'=>240,
'align'=>'right',
'wrappingStyle'=>'square',
'positioning' => 'absolute',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line'
)
);
I also experimented with negative image widths etc., but that did not work neither. Unfortunately, documentation on the whole project is really poor, at least at phpword.readthedocs.org.
I had the same problem too, and there's no answer on the internet to this date. So here's what I came up with:
$section->addImage('image.png', array(
'width' => 40,
'height' => 40,
'wrappingStyle' => 'square',
'positioning' => 'absolute',
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line',
));
I'm trying to add a watermark to all my videos being processed through Amazon elastic transcoder but I can't get it to working.
I created the preset with one watermark set(BottomRight) as in docs.
Here's my PHP source
$output = array(
'Key' => $folderNameOut,
'PresetId' => '139450346',
'ThumbnailPattern' => 'thumbs/filename-{count}',
'Watermarks' => array(
'InputKey' => 'watermark/watermark.png',
'PresetWatermarkId' => 'BottomRight'
));
I tried putting the watermark image in both thumbs and video buckets, even HTTP URL but doesn't work.
Can someone help me with this?
There is a missing array inside the watermarks array
$output = array(
'Key' => $folderNameOut,
'PresetId' => '139450346',
'ThumbnailPattern' => 'thumbs/filename-{count}',
'Watermarks' => array(
array(
'InputKey' => 'watermark/watermark.png',
'PresetWatermarkId' => 'BottomRight'
)
));
I am currently using the MeioUpload Plugin located here:
MeioUpload
The file uploading is all working like a charm, but the thumbnails are not being generated.
Has anyone else had this issue? I am using cakePHP 2.1.
I have followed the readme file strictly.
I was able to get this working by adding this code into the model:
class Image extends AppModel {
var $actsAs = array(
'MeioUpload.MeioUpload' => array(
'filename' => array(
'thumbsizes' => array(
'320x90' => array(
'width' => 320,
'height' => 90
)
)
)
)
);
}
You can vary the size of the thumbnail with the given parameters above.