file size imagemagick thumbnails - php

I need to create thumbnails with imagemagick.. but the file size of the thumbnails is very LARGE!
convert -resize 80x80 -quality 70 file.jpg file-thumb.jpg
example:
file.jpg (1100x825px, 75kb) => file-thumb.jpg (80x60px, 29kb)
It just don't give any sense the thumbs ends up so large!? What am I doing wrong?

Use this instead:
convert file.jpg -thumbnail 80x80 -quality 70 file-thumb.jpg
This strips all EXIF data etc. but keeps the color profile.
Note the image is read in first.

Related

ImageMagick File is too Big

I'm working with imagemagick to convert images from .tiff to .jpeg and make its thumbanils. The converstion from .tiff into .jpeg is OK but the problem comes when I want use imagemagick to move to other folders with others resolutions and creating its thumbnails. Imagemagick says that image in $path.$destinationPath.$ref.".jpeg" is too big but that image doesn't exist...
-Here it is my code:
exec("/usr/bin/convert ".$tiffPath.$ref.".tiff ".$CommonPath.$sourcePath.$ref.".jpeg");
// Ok until here
if (!file_exists($CommonPath.$destinationPath.$ref.".jpeg"))
{
$executa = "/usr/bin/convert -size 800x800 ".$CommonPath.$sourcePath.$ref.".jpeg -thumbnail 800x800 ".$path.$destinationPath.$ref.".jpeg";
exec($executa);
}
Imagemagick returns the following:
convert: unable to open image $CommonPath.$destinationPath.$ref.".jpeg": File is too big # error/blob.c/OpenBlob/2589.
Thanks in advance!
Your second ImageMagick command is malformed. You have:
$executa = "/usr/bin/convert -size 800x800 ".$CommonPath.$sourcePath.$ref.".jpeg -thumbnail 800x800 ".$path.$destinationPath.$ref.".jpeg";
The -size 800x800 is for creating a new image via xc: or canvas:. It may be confusing the command line to think you have two input images. It is certainly not needed. Try removing it, such as
$executa = "/usr/bin/convert ".$CommonPath.$sourcePath.$ref.".jpeg -thumbnail 800x800 ".$path.$destinationPath.$ref.".jpeg";

Pdf preview with imageMagick in php

I am looking for the simplest way of generating image preview from the first page of a pdf file. I have found a nice tutorial, however the code is not complete there. What is the missing part?
In ImageMagick from PHP exec()
exec("convert -density XX image.pdf[0] -resize YY% preview.png")
where XX is the desired density (nominal is 72) but I use something like 288=4*72) to get good quality and YY is the corresponding percent to reduce the image, such as 25%. The [0] means to process only the first page of the pdf.
exec("convert -density 288 image.pdf[0] -resize 25% preview.png")
Adjust these arguments to get the desired output size. You can change png to jpg, but you should then add -quality ZZ before the output to set the jpg compression quality. Values are 0 to 100, nominal for ImageMagick is to use 92.

imagemagick export jpg / png appearing inverted

I am using the imagemagick library to create a png or jpg from 2 images. The jpg / png is creating fine but one of the layered images appear inverted. It should have a white background but instead has black.
I have an uploader script which resizes the image and saves to an upload folder:
$maxsizeHeight=113; // MAX HEIGHT
// create new Imagick object
$image = new Imagick($_FILES["fileToUpload"]["tmp_name"]);
// RESIZES WIDTH TO MATCH HEIGHT OF 100
$image->resizeImage(0,$maxsizeHeight,Imagick::FILTER_LANCZOS,1);
// Set to use jpeg compression
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
// Set compression level (1 lowest quality, 100 highest quality)
$image->setImageCompressionQuality(75);
// Strip out unneeded meta data
$image->stripImage();
// Writes resultant image to output directory
$image->writeImage($target_file);
// Destroys Imagick object, freeing allocated resources in the process
$image->destroy();
Then the second part i combine with a background image:
exec("convert $backgroundimg -interline-spacing 4 -font 'arial' -fill black -pointsize 16 -annotate +220+520 \"$newtext \" null: $logoPath -geometry +$POS_x+$POS_y -layers composite -layers optimize $save_file");
However, i get the following:

How to increase quality of image through imagemagick binary convert?

I'm working in an image conversion using imageMagick binary convert. When i resize a small image into a larger image and also increase the quality of image.
Here's my sample code:
$img = 'old_image.png';
$path1= 'new_img.png';
exec("convert $img -quality 100% -density 600 -resize 2480x3508 -depth 400 $path1");
When i used this command its working fine and it convert large image with loss of quality.
When i need to increase quality by using sharpen 50% code in exec command it doesn't create a proper image and no response in exec command.
$img = 'old_image.png';
$path1= 'new_img.png';
exec("convert $img -sharpen 99% -quality 100% -density 600 -resize 2480x3508 -depth 400 $path1");
Here I'm using image magick binary convert. How to achieve this image quality. Any help would be appreciated.
Think sharpen works like blur and takes an argument of {radius}x{sigma}
What version are you using? Maybe look at some of the docs that correspond to it...
http://www.imagemagick.org/Usage/blur

Resizing animated .gifs with ImageMagick

I know this has been asked in a few different ways before but I am running into what seems to be a unique problem. I am using the following code to resize animated .gif images:
convert $image -coalesce $image
convert -layers OptimizeTransparency -quality 60 -size 220x220 $image -resize 220 +profile '*' $thumb`
In theory this should generate a thumbnailed/resized version of the .gif at 220px X 220px and keep it at a reasonable size by reducing quality and optimizing transparency, but in production it takes a 255kb .gif and turns it into a 1.5mb thumbnail. What is wrong with this code and how can I create more optimized .gif thumbnails?

Categories