Gimp: How to batch resize ONE image in multiple sizes and export them? - plugins

Is there any way to resize an image (jpg/ jpeg)on a range of predefined sizes and export at once on Gimp? (same image-different sizes batch scale and batch export).
Thank you!

From the Gimp GUI, there is a script/plug-in for this, see ofn-export-sizes here(*).
If you want to do that in batch, it is a lot easier/faster to use ImageMagick, which is designed to be used from a shell script:
magick convert input.jpg -resize 500x output-500px.jpg
(here 500x means resize to 500px wide and keep aspect ratio, you can otherwise set
height, width or both). You can even apply a bit of sharpening to compensate for the blur:
magick convert input.jpg -resize 500x -sharpen 0x1.0 output-500px.jpg
For more info, there is a rather active stream of ImageMagick questions here on SO.
(*) Note that in Gimp, a script usable in batch doesn't need to be a plugin, this is required only if you want to use the script from the GUI.

You can do that in Imagemagick command line. For Imagemagick 6 on Unix:
convert image.jpg -write mpr:img +delete \
\( mpr:img -resize W1xH1 +write result1.jpg \) \
\( mpr:img -resize W2xH2 +write result2.jpg \) \
\( mpr:img -resize W3xH3 +write result3.jpg \) \
...
null:
If on Windows
convert image.jpg -write mpr:img +delete ^
( mpr:img -resize W1xH1 +write result1.jpg ) ^
( mpr:img -resize W2xH2 +write result2.jpg ) ^
( mpr:img -resize W3xH3 +write result3.jpg ) ^
...
null:
If on Imagemagick 7, change convert to magick

Related

I want to combine images of different sizes. (Image Magick)

I want to combine 1.png and 2.png
When I combine the two files, I want to change the height of 2.png to the height of 1.png
I used the append command, but I didn't get the result I wanted.
Below is the command I used.
convert +append 1.png 2.png result.png
Please teach me the way!! Thanks !
image
In Imagemagick 6, you would need to get the height of image 1 first in a separate command. For example on a Unix-based system:
ht=`convert image1.png -format "%h" info:`
convert image1.png \( image2.png -resize x${ht} \) +append result.png
In Imagemagick 7, you can do it all in one command line:
magick image1.png -set option:ht "%ht" \( image2.png -resize "x%[ht]" +append result.png
Example:
Input
ht=`convert monet2.jpg -format "%h" info:`
convert monet2.jpg \( zelda1.jpg -resize x${ht} \) +append result.png
Result:
convert -append img1.png img2.png result.png

ImageMagick: composite 4 edges from one image into another, side-by-side

I'm using Perl 5.16 with ImageMagick 6.8 (probably old by now, but it works :). I'm trying to extract all 4 edge regions from one image and composite them into another image, side-by-side, oriented vertically.
I can extract edges and rotate them, but I can't get the offset in the target image right. The edges end up on top of each other. I tried x=>$marg, translate=>"$marg,0", geometry with an offset: no dice. Variables: $marg = the edge width, $im = source, $im2 = target, $ext = extracted region
# left edge
$ext=sprintf("%dx%d+%d+%d",$marg,$h,0,0);
$res=$im2->Composite(image=>$im,compose=>Over,extract=>$ext);
# top edge
$ext=sprintf("%dx%d+%d+%d",$w,$marg,0,0);
$geo=sprintf("%dx%d+%d+%d",$marg,$h,0,0);
$res=$im2->Composite(image=>$im,compose=>Over,extract=>$ext,rotate=>90,translate=>"$marg,0");
I haven't used the PerlMagick bindings for years, but I imagine you would want to create each of your 4 edge strips and then use +append to lay them out horizontally, side-by-side. Here's a crude example, just in Terminal:
magick -size 20x50 xc:red xc:lime xc:blue +append result.png
More specifically addressing your question, and starting with this image:
that would look like this:
#!/bin/bash
magick ~/sample/images/blocks-RGB.png -resize 100x100 +repage -write MPR:orig +delete \
\( MPR:orig -gravity northwest -crop 30x+0+0 \) \
\( MPR:orig -gravity northwest -crop x30+0+0 -rotate 90 \) \
\( MPR:orig -gravity southwest -crop x30+0+0 -rotate 90 \) \
\( MPR:orig -gravity northeast -crop 30x+0+0 \) \
+append result.png
Hopefully you can see the parallels with PerlMagick. The first line creates a copy of the image to work with, the second line crops the left edge, the third line crops the top edge, the fourth line crops the bottom edge, the fifth line crops the right edge and the last line appends the four cropped pieces side-by-side.

Imagemagick to merge and mask images

I recently started working with Imagemagick and I had a problem that needs to be solved.
I have such a thumbnail.
And there is such a mask.
I need to get this image on the output.
I looked through this link http://www.imagemagick.org/Usage/thumbnails/ I tried everything there, but I did not get success ((
I hope you will help me.
This should give you a result very much like your example...
convert mask.png image.png -gravity north -composite \
mask.png -compose copyopacity -composite result.png
You can adjust the positioning of the overlay by including something like "-geometry -10+0" before the first composite.
To use this command in Windows you'll need to change that continued line backslash "\" to a caret "^".
In Imagemagick, you should extract the alpha channel of your mask and put that into the alpha channel of your other image. So try
(unix syntax)
convert KlQZ6.png \( 7k9a9.png -alpha extract \) -alpha off -compose copy_opacity -composite result.png
(windows syntax)
convert KlQZ6.png ( 7k9a9.png -alpha extract ) -alpha off -compose copy_opacity -composite result.png

Image reflection using imagemagick command line?

Original Image
convert image.jpg -scale 310x496\! scaled.png
convert scaled.png +clone -flip -crop 310x150 -compose Dst -composite out/shadow.png
convert -size 310x150 -alpha set gradient:rgba\(255,0,255,0.6\)-rgba\(255,255,0,0.50\) out/grad.png
convert out/shadow.png out/grad.png -compose Dst_Out -composite out/shadow_gradiented.png
convert shadow_gradiented.png out/shadowed.png -append out/final.png
I am getting following output
But I want my output to be like following.
What am i doing wrong? Suggest me.
Additional:
Is there any way I can make all in one command.
Not certain what you are trying to achieve, but this might get you started:
convert wolf.jpg -scale 310x496\! \
\( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.6" \) -append result.png
If you want the alpha tailing off, try a formula that is a function of j (the distance from the top of the reflection) and h (the total height of the reflection).
convert wolf.jpg -scale 310x496\! \
\( +clone -flip -crop x150+0+0\! -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png
If you want the code to be a bit more generic, and less dependent on actual sizes, you could change the height of the reflection to, say 1/4, of the height of the original (note the change from convert to magick)
magick wolf.jpg -scale 310x496\! \
\( +clone -flip -crop "x%[fx:h/4]+0+0\!" -alpha set -channel A -fx "0.8-(0.6*j)/h" \) -append result.png

How to have multiple favicon sizes, yet serve only a 16x16 by default?

Generally it is considered good practice to serve favicon.ico in multiple sizes, because that way it looks better when a shortcut is made or the site is pinned (IE9). The size of a favicon easily increases tenfold by doing so though, which results in slower site loading (in my case the 16x16 favicon is 1kb, the 16, 32, 64=30kb).
Sites like Facebook and Yahoo serve a 16x16 favicon by default that is <1kb, but when you pin these sites, the image used is proper size. I assume the larger picture is loaded only when needed, which fixes the dilemma. I have unsuccessfully been trying to figure out how these sites do this. Does anybody know this?
Update:
My original answer is below, however, since writing this post I believe there may be a better way to handle Favicons with HTML 5. I would create a 32x32 favicon (only that size) for Internet Explorer 9 and below but use other methods for creating higher resolution favicons (PNG file type) for other browsers including mobile devices. You can see my answer here for additional information.
Original Answer to Question:
Here is how it can be done:
Download png2ico. Extract to c:\
Create your Icons in your favorite program. Create a 64x64, 32x32, 16x16. (Note: 64x64 is probably not needed and will increase file size. However, use at least 32x32 and 16x16) Save as icon-64.png (for 64x64 size) icon-32.png (32x32) and icon-16.png (16x16) in the same folder as png2ico. Keep the colors to a minimum.
Open Command Prompt - Change directories to the png2ico folder. (cd \png2ico)
Once in the right directory run this command:
png2ico.exe favicon.ico --colors 16 icon-64.png icon-32.png icon-16.png
Note: The difference in file size for the addition of a 64x64 size icon increased the file by 2kb. I would just use 32x32 and 16x16. (Run same code as above removing icon-64.png)
Grab the favicon.ico file from the png2ico folder. Upload it to the server add <link rel="shortcut icon" href="http://example.com/favicon.ico" /> to the header and you are good to go.
While you are at it go ahead and create Icons for iPad and iPhone. You can find more info on recommended sizes here and how to implement them into your site.
Also more general info on Favicons can be found here.
Note: I do not know if this is how Facebook or Yahoo do theirs but this answers your question of how it can be done.
The Facebook "favicon.ico" contains two sizes: 16x16 and 32x32. I'm sure you know how to combine two ico images into one, however, the "trick" is they're using two extremely optimized images.
I've found that Photoshop creates bloated PNG files, and bloated ICO files. (Note: Photoshop requires a plugin to create ICO files.)
The best way I've found to create tiny, optimized ICO files is to use a well-known free image editor called "Gimp". In short, just follow this tutorial for creating ICO files:
https://www.catalyst.net.nz/news/creating-multi-resolution-favicon-including-transparency-gimp
Important Tip: When you get to the step for saving your .ico image and you can specify the bits-per-pixel (bpp), change it to 4bpp or something similiar (you'll have to experiment to see how low you can go without degrading the image quality).
Using the instructions above, I was able to create a 1kb favicon that contains 16x16 and 32x32 images. In comparison, the smallest I could get the same favicon using Photoshop, plugins, and various other tools was 5kb.
Or you could just log into any linux box with ImageMagick installed, rename your source image (with a resolution of at least 256x256 pixels and a PNG format file) to 'favicon.png', and run the following command:
convert favicon.png -bordercolor white -border 0 \
\( -clone 0 -resize 16x16 \) \
\( -clone 0 -resize 32x32 \) \
\( -clone 0 -resize 48x48 \) \
\( -clone 0 -resize 57x57 \) \
\( -clone 0 -resize 64x64 \) \
\( -clone 0 -resize 72x72 \) \
\( -clone 0 -resize 110x110 \) \
\( -clone 0 -resize 114x114 \) \
\( -clone 0 -resize 120x120 \) \
\( -clone 0 -resize 128x128 \) \
\( -clone 0 -resize 144x144 \) \
\( -clone 0 -resize 152x152 \) \
\( -clone 0 -resize 180x180 \) \
\( -clone 0 -resize 228x228 \) \
-delete 0 -alpha off -colors 256 favicon.ico
And you'll have your favicon.ico with most well-known formats baked right into one file.
Also, be sure to checkout the favicon cheat sheet # https://github.com/audreyr/favicon-cheat-sheet for more favicon information.
Windows batch file, which creates multiple sized .PNGs and merge them to one .ICO file:
#echo off
set inkScape="C:\SOFTWARE\GRAPHIC\INKSCAPE\inkscape.exe"
set imageMagick="C:\SOFTWARE\DEVELOPER\IMAGEMAGICK\magick.exe"
set fileName=favicon
set importType=svg
set exportType=png
set exportDpi=300
set imageSizes=(16 24 32 48 57 60 64 70 72 76 96 114 120 128 144 150 152 180 192 196 256 300 320 400 450 460 480 512 600)
for %%s in %imageSizes% do (
%inkScape% -z -f %~dp0%fileName%.%importType% -w %%s -h %%s -e %~dp0%fileName%-%%sx%%s.%exportType% -d %exportDpi%
echo CREATED: %fileName%-%%sx%%s.%exportType%
set e=%fileName%-%%sx%%s.%exportType%
call :concat (e)
)
%imageMagick% %exportFileNames%"%~dp0%fileName%.ico"
echo MERGED IN: %fileName%.ico
pause goto :eof
:concat (e) (
set exportFileNames=%exportFileNames%"%~dp0%e%"
)
If you don't need the .PNG files, you can delete (or remove) them by del FILE or you save all PNGs inside a directory you can remove (after %imageMagick% %exportFileNames%"%~dp0%fileName%.ico").
Hope it helps somebody. :)
If you like scripts, I wrote one to convert any image to a multi-resolution favicon using ImageMagick.
http://blog.lavoie.sl/2012/11/multi-resolution-favicon-using-imagemagick.html
For your question about why Facebook and Yahoo are able to have high-res "pinned" images, it is because they also have apple-touch-icon and og:image.