[SOLVED]Add border only on bottom and calculate height from width of image

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
TomTomek
Posts: 5
Joined: 2018-02-28T02:22:14-07:00
Authentication code: 1152

[SOLVED]Add border only on bottom and calculate height from width of image

Post by TomTomek »

Since I'm new here I would like to say Hello :)

What I need is to add black border at bottom of my image. But I need that the height of that added border/stripe to be calulated from the width of ma original image. For example mi image is 3500x4000. I need to add 5% of width of my image to the bottom. Oh and one very important thing. I need it to be in one line. Is it possible ?

I don't know what to put instead of ???

Code: Select all

convert source_file.tiff -gravity south -background black -splice 0x ???5% output.jpg 
Last edited by TomTomek on 2018-02-28T13:17:51-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add border only on bottom and calculate height from width of image

Post by snibgo »

What version of IM? In v7, you can have fx expression in splice, eg:

Code: Select all

-splice 0x%[fx:w*0.05]
In v6, you can't have fx in splice, but you can in SRT viewports. The code isn't pretty.
snibgo's IM pages: im.snibgo.com
TomTomek
Posts: 5
Joined: 2018-02-28T02:22:14-07:00
Authentication code: 1152

Re: Add border only on bottom and calculate height from width of image

Post by TomTomek »

Ok it works... I guess I needed to use magick.exe instead of convert :P My bad. Thank You Sir! Works like a charm :)
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Add border only on bottom and calculate height from width of image

Post by GeeMack »

TomTomek wrote: 2018-02-28T02:35:19-07:00What I need is to add black border at bottom of my image. But I need that the height of that added border/stripe to be calulated from the width of ma original image. For example mi image is 3500x4000. I need to add 5% of width of my image to the bottom. Oh and one very important thing. I need it to be in one line. Is it possible ?
There are several ways to get this result. The example snibgo provided may be the simplest. With IM7 you can use "-extent" to accomplish the same thing like this...

Code: Select all

magick source_file.tiff -background black -extent 0x%[fx:w*0.05+h] output.jpg
Also, as snibgo mentioned, it can be done using IM6, but it's a bit more complicated...

Code: Select all

convert source_file.tiff -virtual-pixel black -set option:distort:viewport %[w]x%[fx:w*0.05+h] -distort SRT 0 output.jpg
TomTomek
Posts: 5
Joined: 2018-02-28T02:22:14-07:00
Authentication code: 1152

Re: Add border only on bottom and calculate height from width of image

Post by TomTomek »

@GeeMack Thank You for your answer :) Maybe I'll need this in the future.
I don't want to (or maybe I should?) make another topic so I'll ask here.

I need to add a second image to the source image at the bottom but would like the second image to be scaled in this way:
second image = 0.35 * width of the source image
Final image should be with it's original width.

I can use whatever IM version is needed for shortest command line instructions :)
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Add border only on bottom and calculate height from width of image

Post by GeeMack »

TomTomek wrote: 2018-02-28T07:45:19-07:00I need to add a second image to the source image at the bottom but would like the second image to be scaled in this way:
second image = 0.35 * width of the source image
Final image should be with it's original width.
I'm not quite sure I understand the question, but you can read many images into an IM command and perform various operations on them conditionally. A command like this would read in two images, scale the width of the second to 0.35 the width of the first while maintaining its proportions, and append it to the bottom of the first...

Code: Select all

magick img1.png img2.png -resize %[fx:t?u.w*0.35:u.w]x -append output.png
Doing those sorts of conditional operations and calculations is what makes IM7 especially powerful and versatile. You can learn more about the construction of that FX expression at THIS link.
TomTomek
Posts: 5
Joined: 2018-02-28T02:22:14-07:00
Authentication code: 1152

Re: Add border only on bottom and calculate height from width of image

Post by TomTomek »

I am very sorry, but my English is not as good as I would like (I'm still learning). Anyway, You understood well what I meant :) Thank you very much for the answer.
I'm writing a program for my institution that uses IM as a image converter (we have a lot of them). Well to be honest it's rather GUI and reporting app, since the main job is done by IM.
We have certain standards for storing and displaying images on the internet. So far, we've used a shell script, but I can only say that it exists. Basically, it does its job (batch converting images) quite well, but my goal is to create an application that will be convenient for less advanced users, because we are only one of many state institutions in our country and We share new solutions with each other. Besides, I think that I can improve this script that we're using at the moment,by reducing the number of steps that must be taken to achieve what we need. In addition, my application is to make some more sofisticated reports after conversions is done and present them in an accessible way, for example for the head management ;)
That's why I learned FreePascal (Lazarus IDE) enough to be able to realize my idea, and now I'm learning how to use ImageMagick :). Our IT/programmers department is still busy with 'something' so I decided that I would do something myself (WE NEED TOOLS :P)
So since You and others helped me ALOT I would love to add a big THANK YOU in the credits in my App :) If You are willing to agree of course :) Although, to be honest, even if the application will be widely available, I doubt whether it will be useful to someone outside the archive network in my country. Anyway... Once again THANK YOU :)
GeeMack wrote: 2018-02-28T08:24:02-07:00
I'm not quite sure I understand the question, but you can read many images into an IM command and perform various operations on them conditionally. A command like this would read in two images, scale the width of the second to 0.35 the width of the first while maintaining its proportions, and append it to the bottom of the first...

Code: Select all

magick img1.png img2.png -resize %[fx:t?u.w*0.35:u.w]x -append output.png
Doing those sorts of conditional operations and calculations is what makes IM7 especially powerful and versatile. You can learn more about the construction of that FX expression at THIS link.
Post Reply