-frame option always provides gray fill bars

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kengentry5000

-frame option always provides gray fill bars

Post by kengentry5000 »

Hi,

I need to create square-shaped high-quality JPEG images. I need to preserve the original dimensions and aspect ratio to the original image, just need to pad out either top/bottom or left/right to make the image square.

I am trying to using the 'Convert' utility in ImageMagick with the following invocation:

convert 8.jpg -quality 90 -frame 182x0+0+0 8-mod.jpg

I am computing the frame dimensions needed beforehand and this has worked great with one catch - the borders on the sides of the image are ALWAYS gray in color. I need to make the padding white in color.

I have tried many variations on this command to get the borders, including the following:

convert 8.jpg -quality 90 -frame 182x0+0+0 -mattecolor white 8-mod.jpg
convert 8.jpg -quality 90 -frame 182x0+0+0 -background white 8-mod.jpg
convert 8.jpg -quality 90 -frame 182x0+0+0 -background #000000 8-mod.jpg
convert 8.jpg -quality 90 -frame 182x0+0+0 -transparent-color white 8-mod.jpg
convert 8.jpg -quality 90 -frame 182x0+0+0 -fill #000000 8-mod.jpg
convert 8.jpg -quality 90 -frame 182x0+0+0 -bordercolor #000000 8-mod.jpg

I keep getting gray colored bars on either side of the image. This is making me crazy!

Can anyone please help here? Is this a problem with using the wrong type of color feature (-mattecolor, -bordercolor, etc.) with the -frame option? Is it a parameter ordering problem?

Any help is greatly appreciated.

Ken
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: -frame option always provides gray fill bars

Post by Bonzo »

You could try this:

Code: Select all

exec("/usr/local/bin/convert -size 200x200 xc:white 8.jpg -gravity center -composite 8_mod.jpg "); 
Note: I would not use - in file names.
kengentry5000

Re: -frame option always provides gray fill bars

Post by kengentry5000 »

Thank you. That is exactly what I needed and it is actually a more simplified technique for sizing than what I was using.

Ken
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: -frame option always provides gray fill bars

Post by Bonzo »

The bit of code is not sizing - its just combining the photo with a background !

It is creating a white background 200 x 200 and placing the image in the center of the background.

I will add a bit of resizing code - I didn't realize you wanted to resize the image.

Code: Select all

exec("/usr/local/bin/convert -size 200x200 xc:white 8.jpg -resize 200x200 -gravity center -composite 8_mod.jpg"); 
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: -frame option always provides gray fill bars

Post by Bonzo »

My last post does not work :(
I thought this would cure it but it does not work either

Code: Select all

exec("/usr/local/bin/convert -size 200x200 xc:white /(8.jpg -resize 200x200 /) -gravity center -composite 8_mod.jpg"); 
Not as neat but it works; perhaps Anthony will look at this and put me right on the code above !

Code: Select all

exec("/usr/local/bin/convert 8.jpg -resize 250x250 temp.jpg"); 

exec("/usr/local/bin/convert -size 300x300 xc:white temp.jpg -gravity center -composite 8_mod.jpg"); 

unlink("temp.jpg");
Instead of saving the temporary image as a jpg it may be better to use a loss less format to keep the quality.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -frame option always provides gray fill bars

Post by anthony »

You problem is because you are not setting the -mattecolor before the -frame operator that uses it!!!!!

Also frame does not use image size in its arguments, it only uses the number of pixels to add to around the outside of the image.

See IM Examples, Frame....
http://www.imagemagick.org/Usage/crop/#frame
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Alan C

Re: -frame option always provides gray fill bars

Post by Alan C »

hi,
I know this is a really old thread but I picked it up early 2008 and followed some of the usage in it with excellent results but my hosting provider has recently upgraded the server to im 6.4.4 and it seems to have caused problems, specifically my thumbnails are now appearing mono instead of full colour.

Here is the detail of what I am doing . . .

I need to resize a folder full of images to various sizes, 400 and 240 pixels on the long edge, and produce 180 pixel squares regardless of the size or orientation of the original image, so that when I line them up with css the captions under them all line up too. I put these into sub-folders, and they are all just how they should be, including the smallest ones.

I take a 180 pixel white square and save it in the .miff intermediate format, then resize my original down to 180 pixels on the long edge and save it as sq_temp.miff, now I take this thumbnail and composite it with the sq_temp.miff image. My command looks like this . . .

composite -gravity center /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/sq_temp.miff /home/sitename/public_html/artists/alan_C/test_images/square.miff /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/dsc02314.jpg

all this was working perfectly for months before the upgrade, now, it still works but the final square thumbnails appear as monochrome when viewed on the page. Their sizes and orientations are still just how they were before.

Any advice or suggestions on this issue are welcome - and that includes different ways of tackling the formation of the thumbnails :-)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -frame option always provides gray fill bars

Post by fmw42 »

Alan C wrote:hi,
I know this is a really old thread but I picked it up early 2008 and followed some of the usage in it with excellent results but my hosting provider has recently upgraded the server to im 6.4.4 and it seems to have caused problems, specifically my thumbnails are now appearing mono instead of full colour.

Here is the detail of what I am doing . . .

I need to resize a folder full of images to various sizes, 400 and 240 pixels on the long edge, and produce 180 pixel squares regardless of the size or orientation of the original image, so that when I line them up with css the captions under them all line up too. I put these into sub-folders, and they are all just how they should be, including the smallest ones.

I take a 180 pixel white square and save it in the .miff intermediate format, then resize my original down to 180 pixels on the long edge and save it as sq_temp.miff, now I take this thumbnail and composite it with the sq_temp.miff image. My command looks like this . . .

composite -gravity center /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/sq_temp.miff /home/sitename/public_html/artists/alan_C/test_images/square.miff /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/dsc02314.jpg

all this was working perfectly for months before the upgrade, now, it still works but the final square thumbnails appear as monochrome when viewed on the page. Their sizes and orientations are still just how they were before.

Any advice or suggestions on this issue are welcome - and that includes different ways of tackling the formation of the thumbnails :-)
The use of -extent is probably simpler. See http://www.imagemagick.org/Usage/crop/#extent (you need IM 6.2.4 or later for -extent)

Here is an example. I create a 240x200 blue image. Then resize so the longer side is 180, then pad it centered with red so that it is filled out to 180x180:

convert -size 240x200 xc:blue -resize 180x180 -background red -gravity center -extent 180x180 tmp_blue_red.jpg

You can change the -size 240x200 xc:blue to your input image and change the background color from red to white or any other color (including "none" for transparent, but you need output format of png or gif if transparent)

You can also use -thumbnail 180x180 rather than -resize 180x180, if you want smaller filesizes with ancillary data stripped out. See http://www.imagemagick.org/script/comma ... #thumbnail
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -frame option always provides gray fill bars

Post by anthony »

Alan C wrote:

Code: Select all

composite -gravity center /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/sq_temp.miff /home/sitename/public_html/artists/alan_C/test_images/square.miff /home/sitename/public_html/artists/alan_C/test_images/sq_thumbs/dsc02314.jpg
all this was working perfectly for months before the upgrade, now, it still works but the final square thumbnails appear as monochrome when viewed on the page. Their sizes and orientations are still just how they were before.
This should still be working. can you give us links to the input and output images from the above so that we can check what is going on.

However Fred (fmw42) is right about using -extent and -thumbnail, as probably being the better faster solution. It will let you do the whole operation on a single line just as described in the IM Examples, Thumbnails
http://www.imagemagick.org/Usage/thumbnails/#pad
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Alan C

Re: -frame option always provides gray fill bars

Post by Alan C »

fmw42 and Anthony
first - thank you for responding :-) it's so nice that you took the trouble - it's appreciated

I did not know about -extent, it does just what I need so I will revisit my code and re-work it

Chances are that there is something odd about my original code, but better that I know it now, so I put in some more echo statements so I can give you the commands that I am executing - the parameters are filled in as constants and using sprint, so the code is not obvious when you read it. This way you will not have to pick it apart too much. I will leave in the full paths.
0 - form a white square

convert -size 180x180 xc:white /home/hartgallery/public_html/artists/chard/test_images/square.miff

1 - produce reduced size thumbnail

convert /home/hartgallery/public_html/artists/chard/test_images/dsc02314.jpg -resize 175x -quality 65 /home/hartgallery/public_html/artists/chard/test_images/sq_thumbs/sq_temp.miff


2 - make the composite

composite -gravity center /home/hartgallery/public_html/artists/chard/test_images/sq_thumbs/sq_temp.miff /home/hartgallery/public_html/artists/chard/test_images/square.miff /home/hartgallery/public_html/artists/chard/test_images/sq_thumbs/dsc02314.jpg

the test images are in
http://hartgallery.co.uk/artists/chard/test_images/
as a temporary measure I have not put an index.htm file into the folder, so you will be able to view the directory and sub-directories where the re-sized images are stored. large contains 400x300 images, medium contains 300x225, thumbs 120x90 and sq_thumbs the 180x180 composites.

and you can see the finished page that the script assembles here
http://hartgallery.co.uk/artists/chard/work.htm

Thanks again for looking
Alan C

. . . later in the day - quick update, I have re-written my code to use extent and it works great, I'm still interested to know what I had amiss though :-)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -frame option always provides gray fill bars

Post by anthony »

Alan C wrote:2 - make the composite

composite -gravity center /home/hartgallery/public_html/artists/chard/test_images/sq_thumbs/sq_temp.miff /home/hartgallery/public_html/artists/chard/test_images/square.miff /home/hartgallery/public_html/artists/chard/test_images/sq_thumbs/dsc02314.jpg
I ran through the sequence and the thumbnailing and composite result came out correct and in color.

I don't know where it is going wrong.

Check your square.miff temporary image and see if it was in color.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Alan C

Re: -frame option always provides gray fill bars

Post by Alan C »

Anthony,
Thank you for checking that out, I am at a loss to explain this, the only thing I can think is that it's something to do with my shared hosting, I know that should not affect it, but I have had strange things happen in the past.

It's working very well now that I've reworked the code to use extent, and thanks to that it's also much faster

Thank you again for your assistance :D
Post Reply