Page 1 of 1

Scale down picture, fill rest with border.

Posted: 2013-10-22T22:09:40-07:00
by Sweptr
I suppose this wil be more a mathematic problem than anythingelse..
I have this Command

Code: Select all

convert   Forvaltningsratten.png -resize 20% -bordercolor  Black -border 200%x200%  20-perc_Förvaltningsratten.png 
Regarding to how much I shrink the original image - the border parameters will be different.
I am have to placed it into a script so I can use variables for the -resize value and the -border value.

Here is my script, which is not working corectly. It gives different output sizes depending to the percentage I have as input parameter

Code: Select all

#!/bin/bash 
ImageSize=$1 #eg 1280*720 
Percent=$2 # eg 30 
Color=$3 

BorderSize=$(bc -l <<< "($ImageSize/($ImageSize*$Percent/100)/2+10)*10") 
 
convert   Forvaltningsratten.png -resize $Percent% -bordercolor  $Color -border \  $BorderSize%x$BorderSize%  $Percent-perc_Forvaltningsratten.png
~
~
~
~

Re: Scale down picture, fill rest with border.

Posted: 2013-10-22T22:47:58-07:00
by snibgo
Your expression is strange. It contains ImageSize twice, and they cancel each other. So the result does not depend on ImageSize.

Re: Scale down picture, fill rest with border.

Posted: 2013-10-22T23:58:19-07:00
by Bonzo
You can use -extent and that is even easier if all your final images are the same size:

Code: Select all

convert input.jpg -resize 500x500 -background blue -gravity center -extent 600x600 output.jpg

Re: Scale down picture, fill rest with border.

Posted: 2013-10-23T07:59:36-07:00
by Sweptr
Bonzo wrote:You can use -extent and that is even easier if all your final images are the same size:

Code: Select all

convert input.jpg -resize 500x500 -background blue -gravity center -extent 600x600 output.jpg
Oh thank you sir.

That was exactly what I needed. :D

Re: Scale down picture, fill rest with border.

Posted: 2013-10-23T15:06:53-07:00
by Sweptr
snibgo wrote:Your expression is strange. It contains ImageSize twice, and they cancel each other. So the result does not depend on ImageSize.
At the time writen the code, it was more important to understand what is going on thant make the code pretty.

In this cas eI clearly can see that I
A.. take the size of the whole image,
B. divde it with the size of the whole image multiplied with the value which I use as percent.
C. devide the result with 100 to get the actual percent and then
E. divide the reult with ten.


Why I had to add ten and divide with ten is for now . out of my reach.

I can not gert rid of the imagesize at both ends of the division because the first ImageSize is devided with the result of the second ImageSize and anther divison and multiplication. Try it yourself with some random numbers...

(712/(712*30/100)/2+10)*10)
Is NOT the same as
((30/100)/2+10)*10

Or- did i missunderstand you.?

But I know that my code is wrong, and that's why I come to here in the first place.

I will wait a few days and see If someone can point out the error in my code, then I will mark it as solved anyway - because Bonzo gave me an excellent and better alternative.

Still - I would really love to understand the mathematics behind the scene.

Re: Scale down picture, fill rest with border.

Posted: 2013-10-23T15:19:53-07:00
by snibgo
(712/(712*30/100)/2+10)*10)
Is NOT the same as
((30/100)/2+10)*10
Agreed. But it is the same as ((100/30)/2+10)*10.

Your expression can be simplified:

($ImageSize/($ImageSize*$Percent/100)/2+10)*10
= 500 / $Percent + 100

For example:
(712/(712*30/100)/2+10)*10 = 116.6667
500 / 30 + 100 = 116.6667

Re: Scale down picture, fill rest with border.

Posted: 2013-10-23T15:41:13-07:00
by Sweptr
snibgo wrote:
(712/(712*30/100)/2+10)*10)
Is NOT the same as
((30/100)/2+10)*10
Agreed. But it is the same as ((100/30)/2+10)*10.

Your expression can be simplified:

($ImageSize/($ImageSize*$Percent/100)/2+10)*10
= 500 / $Percent + 100

For example:
(712/(712*30/100)/2+10)*10 = 116.6667
500 / 30 + 100 = 116.6667
Yes, but then I donẗ keep track of how I was thinking.
The equation was wrong anyway - It worked for the particular value of 30 percent, but all other values went wrong.

So I still hope to get help finding the correct method to solve this, though not more needed for this purpose - I bet I will get some use of it in the future.

And yes, I am not very bright in mathematics - but I am stubborn as f****ng h**l, so I often solve my problems anyway.
But on this one, I fault.