Page 1 of 2

composite and backgroud problem

Posted: 2011-01-28T10:27:09-07:00
by alfredopacino
hi, first sorry for my english, im italian.

i'm trying to create a pdf thumbnail with this features:
-size 100x100 (with a A4 format pdf)
- white background
- a little png icon on the south-right side 32x32

exec("convert \"{$strPDF}[0]\" -colorspace RGB -geometry 96x96 -border 50 -gravity center -crop 100x100+0+0 -background white \"thumb_pdf.jpg\"");

this work, but:
- background is grey!why?
- how can i add the icon onto my image? i read 'composite' docs but i cant..:(

for better explain:
- this is what i have now
Image

- what im looking for
Image

- best solution 100x100 img with a inner border on document
Image

Re: composite and backgroud problem

Posted: 2011-01-28T11:00:37-07:00
by Bonzo
Good try but as you say not the result you wanted; try this:

Code: Select all

<?php
$strPDF = "booklet.pdf";

$array=array();
echo "<pre>";
exec("convert -density 300 \"{$strPDF}[0]\" -thumbnail 100x100 -background white -gravity center -extent 100x100 logo.png -gravity southeast -composite thumb_pdf.jpg  2>&1", $array); 
echo "<br>".print_r($array)."<br>";
?>
Some error reporting added that you can comment out or remove.

This was interesting as I did not know you needed to do this as I normaly input the pdf name not the variable in my tests \"{$strPDF}[0]\"

You probably want to post in the user section next time as this is not using Magick wand and you willl probably get more replys.

To make longer lines more user freindly I write my code this way now:

Code: Select all

$cmd = "-density 300 \"{$strPDF}[0]\" -thumbnail 100x100 -background white ".
" -gravity center -extent 100x100 logo.png -gravity southeast -composite";
exec("convert $cmd thumb_pdf.jpg); 

Re: composite and backgroud problem

Posted: 2011-01-28T12:20:09-07:00
by alfredopacino
thanks for show me how i can see error reporting :)

Code: Select all

Array
(
    [0] => convert: unable to open image `logo.png': No such file or directory.
    [1] => convert: unable to open file `logo.png'.
)
i tried yours..wtf? :) i want to create logo.png! why the script try to open image? (directory permission alright)

Re: composite and backgroud problem

Posted: 2011-01-28T12:27:26-07:00
by Bonzo
Change logo.png to the name of the icon you want to put on top of the pdf. You did not say what it was called in your post.

Imagemagick error reporting is not always helpful!

Re: composite and backgroud problem

Posted: 2011-01-28T12:46:36-07:00
by alfredopacino
Bonzo wrote:Change logo.png to the name of the icon you want to put on top of the pdf. You did not say what it was called in your post.
yep i inverted the files :? :)

now results:
Image

thumb on the left and black backgound..why??

ps: can i control jpg compression rate?quality is awful..

Re: composite and backgroud problem

Posted: 2011-01-28T13:14:57-07:00
by Bonzo
What code are you using ?

You can add -quality 100 just before the image save name and increase the -density from 300 to 400 to improve quality

Re: composite and backgroud problem

Posted: 2011-01-28T13:24:27-07:00
by alfredopacino
Bonzo wrote:What code are you using ?

You can add -quality 100 just before the image save name and increase the -density from 300 to 400 to improve quality
yours

Code: Select all

exec("convert -density 300 \"{$strPDF}[0]\" -thumbnail 100x100 -background white -gravity center -extent 100x100 pdf_icon.png -gravity southeast -composite pdfthumb.png  2>&1", $array); 

Re: composite and backgroud problem

Posted: 2011-01-28T14:04:25-07:00
by fmw42
the use of -border requires setting -bordercolor and not -background and usually before -border. Put the settings before the operation.

Re: composite and backgroud problem

Posted: 2011-01-28T16:13:42-07:00
by Bonzo
Thats strange as it worked OK for me; have you tried another pdf as there may be a problem with that one ?

Improve the quality ( -quality has no effect on .png images ? ):

Code: Select all

exec("convert -density 400 \"{$strPDF}[0]\" -thumbnail 100x100 -background white -gravity center -extent 100x100 pdf_icon.png -gravity southeast -composite pdfthumb.png  2>&1", $array); 

Re: composite and backgroud problem

Posted: 2011-01-28T16:49:45-07:00
by alfredopacino
i have ImageMagick 6.2.8..maybe create problem?

for some pdf i see some warnings, but the output files is the same (thumb on the left and black back):

Code: Select all

Array
(
    [0] =>    **** Warning: Fonts with Subtype = /TrueType should be embedded.
    [1] =>                  But Times New Roman is not embedded.
    [2] =>    **** Warning: Fonts with Subtype = /TrueType should be embedded.
    [3] =>                  But Arial,BoldItalic is not embedded.
    [4] =>    **** Warning: Fonts with Subtype = /TrueType should be embedded.
    [5] =>                  But Arial is not embedded.
    [6] =>    **** Warning: Fonts with Subtype = /TrueType should be embedded.
    [7] =>                  But Arial,Bold is not embedded.
    [8] => 
    [9] =>    **** This file had errors that were repaired or ignored.
    [10] =>    **** The file was produced by:
    [11] =>    **** >>>> Microsoft® Office Word 2007 <<<<
    [12] =>    **** Please notify the author of the software that produced this
    [13] =>    **** file that it does not conform to Adobe's published PDF
    [14] =>    **** specification.
    [15] => 
)

Re: composite and backgroud problem

Posted: 2011-01-28T17:11:06-07:00
by fmw42
IM 6.2.8 is very ancient (about 400 versions old) a lot of things were not implemented at that time. You would be best to upgrade if possible.

For example from Anthony's pages:

Before IM version v6.3.2, "-extent" just cleared the memory of any new areas to zero, or straight black. It did not fill the areas with "-background" color.

see http://www.imagemagick.org/Usage/crop/#extent

Re: composite and backgroud problem

Posted: 2011-01-28T17:20:23-07:00
by alfredopacino
im on a shared hosting, dont think they'll updrage the software for me, but i'll ask for.

there isnt a different way for make this for my version?

Re: composite and backgroud problem

Posted: 2011-01-28T18:43:32-07:00
by fmw42
exec("convert \"{$strPDF}[0]\" -colorspace RGB -geometry 96x96 -border 50 -gravity center -crop 100x100+0+0 -background white \"thumb_pdf.jpg\"");
I really don't understand why you have included -geometry 96x96 as it does nothing here. Also why -border 50 unless the resulting pdf is too small (and if you really need it then you need to add -bordercolor white).

The size of the pdf is controlled by -density and not -geometry or -size or -resize. So add the appropriate -density value to make it bigger or smaller.


But try this:

exec("convert -colorspace RGB \"{$strPDF}[0]\" -gravity center -background white -crop 100x100+0+0 +repage \"thumb_pdf.jpg\"");

or for higher quality (supersampling)

exec("convert -colorspace RGB -density 288 \"{$strPDF}[0]\" -resize 25% -gravity center -background white -crop 100x100+0+0 +repage \"thumb_pdf.jpg\"");

If these are too small, then increase the density (above 72)

exec("convert -colorspace RGB -density 150 \"{$strPDF}[0]\" -gravity center -background white -crop 100x100+0+0 +repage \"thumb_pdf.jpg\"");

or if you want to add a white border, use

exec("convert -colorspace RGB \"{$strPDF}[0]\" -gravity center -bordercolor white -border 50 -background white -crop 100x100+0+0 +repage \"thumb_pdf.jpg\"");

etc with the higher quality one

Let us know what you get so we can then try to fine tune it for your needs. Explain if not correct, what is wrong and link to the results.

Re: composite and backgroud problem

Posted: 2011-01-29T02:32:16-07:00
by Bonzo
Try this:

Code: Select all

exec("convert -size 100x100 xc:white \( -density 300 \"{$strPDF}[0]\" -thumbnail 100x100 -unsharp 1.5x1+0.7+0.02 \) -gravity center -composite image-cropped-2.png -gravity southeast -composite thumb_pdf1.jpg  2>&1", $array);
I have also added some sharpening to the pdf but I would say at this size you are not going to get a good quality anyway.

Re: composite and backgroud problem

Posted: 2011-01-29T03:29:20-07:00
by alfredopacino
Bonzo wrote:Try this:

Code: Select all

exec("convert -size 100x100 xc:white \( -density 300 \"{$strPDF}[0]\" -thumbnail 100x100 -unsharp 1.5x1+0.7+0.02 \) -gravity center -composite image-cropped-2.png -gravity southeast -composite thumb_pdf1.jpg  2>&1", $array);
I have also added some sharpening to the pdf but I would say at this size you are not going to get a good quality anyway.
this works..im very very very grateful :D

ps: whats sharpening?