Conditional Resizing

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
salahuddinonline
Posts: 24
Joined: 2013-07-14T03:36:12-07:00
Authentication code: 6789

Conditional Resizing

Post by salahuddinonline »

hi
I am facing problem in this, As I have multiple images to work on but do not want to review there canvases and Sizes
can any one help me out on this,
For Example

if Image is between 475x475 then set canvas as 500x500 with gravity center,
if image size is between 135x135 to 159x159 set gravity center and canvas as 160x160
but do nothing if image size is between 161X161 to 199x199,
and
if image size between 200x200 to 224x224 set gravity center and set canvas as 225x225
but do nothing if image is between 226x226 to 274x274
if image size is between 275x275 to 299x299 set gravity center and canvas as 300x300
but do nothing if image size is between 301X301 to 475x475,

kindly help me out on this,
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conditional Resizing

Post by snibgo »

You probably need to write a script. This would read the image size, and set the new size as needed (although I'm not quite sure what you are trying to do).

What is your platform: Windows, Unix, Mac or other?
snibgo's IM pages: im.snibgo.com
salahuddinonline
Posts: 24
Joined: 2013-07-14T03:36:12-07:00
Authentication code: 6789

Re: Conditional Resizing

Post by salahuddinonline »

I am using linux ubuntu, I understand that I need to write an script but I have told that whatever I need to know how to set canvases in conditional resizing
if Image's size between 475x475 then set canvas as 500x500 with gravity center,
if image size is between 135x135 to 159x159 set gravity center and canvas as 160x160
but do nothing if image size is between 161X161 to 199x199,
and
if image size between 200x200 to 224x224 set gravity center and set canvas as 225x225
but do nothing if image is between 226x226 to 274x274
if image size is between 275x275 to 299x299 set gravity center and canvas as 300x300
but do nothing if image size is between 301X301 to 475x475,
I think I have described what I am looking for,
if anyone can write an script I would be thankful...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conditional Resizing

Post by snibgo »

I don't use Unix so can't help you with the script.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Conditional Resizing

Post by Bonzo »

For the 500x500 canvas you would need to use extent:

Code: Select all

convert input_image -backround white -gravity center -extent 500x500 output_image
Just use the same imagemagick code for each of your sizes and just change the -extent values.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Conditional Resizing

Post by GreenKoopa »

Do you want the images resized (resampled), or are you wanting a border added? A colored border, or a transparent one? Are your initial images always square?

This could be done using only IM, but a script may be easier and more readable.
salahuddinonline
Posts: 24
Joined: 2013-07-14T03:36:12-07:00
Authentication code: 6789

Re: Conditional Resizing

Post by salahuddinonline »

Thanks for Asking Green,
Actually I dont wanna add border or color or any thing like them but I want to just resize canvas and said conditions
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Conditional Resizing

Post by GreenKoopa »

I think Bonzo read your post as asking to place an image on a larger background canvas, which is understandable since you spoke of a canvas and gravity. If this is what you want, your canvas would need a color. If you do not want a background canvas, what do you mean by gravity?

Again, are your initial images always square?

You are asking for a complex conditional resize. Do you have a command working for one image you could give as an example of what you want?
salahuddinonline
Posts: 24
Joined: 2013-07-14T03:36:12-07:00
Authentication code: 6789

Re: Conditional Resizing

Post by salahuddinonline »

/home/$whoamI/Desktop/Images/Originals/
mogrify -path /home/$whoamI/Desktop/Images/converted/ -trim -gravity center -resize 300x300 -extent 300x300 *.jpg

I do not have images in square, but in different Dimensions, For Example 480x320 or 2375x2500
I want to resize images As per conditions given by me,
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Conditional Resizing

Post by GreenKoopa »

Okay, that is a start. To use your example, you begin with a 2375x2500 image. I do not understand which conditional case it falls under? I do not understand what exactly you want done?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conditional Resizing

Post by snibgo »

Confusingly, two threads have been started on this topic, under "Users" and "Developers".

Can a moderator merge them?
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Conditional Resizing

Post by GreenKoopa »

This entire thread can be deleted. All of the useful information is in this thread in the Developers forum.
salahuddinonline
Posts: 24
Joined: 2013-07-14T03:36:12-07:00
Authentication code: 6789

how to remove its shadow and get trimmed and sized

Post by salahuddinonline »

hi there
can any one tell me what should be done if I want to use this image and remove its shadow background is white then trim it edge to edge then resize it with size either X or Y (whichever is larger )
I am using linux ubunto
I want to apply this to whole directory
there is nothing except images in this directory
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Conditional Resizing

Post by snibgo »

This isn't about Conditional Resizing, so start a new thread. And supply an example image.
snibgo's IM pages: im.snibgo.com
Post Reply