Using a .bat file to compress jpg inside a folder imagemagick magick - imagemagick

EDIT (FINAL)
I figured it out!
Step 1: install image magick on windows
Step 2: locate the file magick.exe in program files. keep a copy of this somewhere convenient. you'll be making copies of this everytime you have a folder of photos.
Step 3: Create a batch file, (notepad save as .bat) (e.g. magick.bat) and keep this file in that same convenient location as Step 2. you'll also be making copies of this everytime you have a folder of photos. the batch code as follows:
#ECHO ON
FOR %%a in (*.jpg) DO magick convert %%a -quality 95%% %%~na_small.jpg
PAUSE
Step 4: Copy both .bat and magick.exe into a folder of your photos each time you want to compress the photos inside, then double click the .bat batch file and let it run! Your compressed photos will start appearing!
[sample of how folder looks][1]
I'm really not good at this. I just want to create a .bat file, copy and paste this file into a folder where my photos are, and then double click this file so that I can compress my jpgs
but with my echo on, i can see that it keeps looping the first jpg and then it stops. nothing happens after that. no new files are created either, or overwritten.
can someone point me the proper code to write?
#ECHO ON
pause
for %%A In (*.jpg) do (magick -i "%%A" -quality 85 "%%~nAx.jpg")
PAUSE
thank you
Edit: this is how it looks like with Echo ON
I:\Photos\unsorted\testing>pause
Press any key to continue . . .
I:\Photos\unsorted\testing>for %A In (*.jpg) do (magick -i "%A" -quality 85 "%~nAx.jpg" )
I:\Photos\unsorted\testing>(magick -i "XH1F0270.JPG" -quality 85 "XH1F0270x.jpg" )
I:\Photos\unsorted\testing>pause
Press any key to continue . . .```
[1]: https://i.stack.imgur.com/KhhEx.png

I figured it out!
Step 1: install image magick on windows
Step 2: locate the file magick.exe in program files. keep a copy of this somewhere convenient. you'll be making copies of this everytime you have a folder of photos.
Step 3: Create a batch file, (notepad save as .bat) (e.g. magick.bat) and keep this file in that same convenient location as Step 2. you'll also be making copies of this everytime you have a folder of photos. the batch code as follows:
#ECHO ON
FOR %%a in (*.jpg) DO magick convert %%a -quality 95%% %%~na_small.jpg
PAUSE
Step 4: Copy both .bat and magick.exe into a folder of your photos each time you want to compress the photos inside, then double click the .bat batch file and let it run! Your compressed photos will start appearing!

Related

Xcode: How can I rename all file extensions easily without doing it one by one, without loosing all the references to the targets?

In Xcode, I would like to rename all the files extensions from PNG to JPG easily.
I tried find and replace, but it only changes the names in storyboards, classes etc... not the file names.
Find & Replace:
Files:
References to targets:
If I change the name only physically, it lots the file :
Is there a way to do it easily?
You'll need multiple steps to achieve this.
Do your find & replace approach like you described
For renaming the files you do the following in the terminal.
brew install rename
cd <path to your folder> This is important. Make sure you are in the right folder, otherwise you rename more files than you want ;-).
find . -exec rename -S '.png' '.jpg' {} + This replaces every occurance of png to jpg recursively (this means including subfolders)
You have to rename the file references inside your Xcode-Project and all occurences in your the Assets.xcassets file
Close Xcode.
cd <path to your folder>
find . -type f -name 'project.pbxproj' -exec sed -i '' s/.png/.jpg/ {} +
find . -type f -name 'Contents.json' -exec sed -i '' s/.png/.jpg/ {} +
Open Xcode again
Please make a commit or a backup before such operations.

docker add extract to custom directory

A docker add will nicely extract the supplied compressed file into the directory specified in the zip/tar file
How can I extract it into a different directory?
Eg. if the file extracts to /myfile but I would prefer /otherFile
Don't believe there's any way to do this just using the ADD instruction. ADD supports a target directory obviously, like ADD ["<src>", "<dest>"] however it's still going to extract into the dir you have in the tar within that.
2 options, either rename the dir in the tar or do a RUN mv myfile otherfile after adding.
Is there a specific reason you need it to be named something in particular?
Think about this scenario where you build a tomcat image,
ADD apache-tomcat-8.0.48.tar.gz /opt
This cmd will extract the tar to /opt/apache-tomcat-8.0.48 , if you don't like the long folder name(apache-tomcat-8.0.48) then the requirement happens.

How to batch convert JPG image gallery to BPG image format

How to convert whole image gallery or family album from JPG to BPG image format?
I'm looking for some batch conversion tool, application or script on Windows platform.
Input directory must be processed recursively and image quality should be preserved.
Linux command line fragment I use for this task, with current directory being gallery of '*.JPG' files, without subdirectories.
parallel -i sh -c 'convert -quality 100 {} -scale "1280x1000>" {}.png && bpgenc -q 30 {}.png -o {}.bpg && rm -f {}.png' -- *.JPG
You may adjust (or remove) resizing and change -q 30 to lower value for more quality.
It depends on ImageMagick and bpgenc.
To run in on Windows, you probably will need Cygwin.
Look at
http://www.romeolight.com/products/bpgconv/
for nice Windows converter.
2 things to mention: Currently there is options menu in top right of window. And all BPG pictures are saved into folder on your desktop called bpg_encoded.
Martin

How to flop multiple images using imagemagik?

I tried to flip horizontally the images in a specific folder using ImageMagik. But the mogrify -flop *jpg is changing all the images in their mirror images. I want to keep the initial images and for the flopped ones I want to rename them as *_flop.jpg. I am stuck: How to do it?
Assuming you are on Linux or OSX, like this:
#!/bin/bash
for f in *.jpg; do
new="${f%%.jpg}_flop.jpg"
echo convert "$f" -flop "$new"
done
At the moment, it does nothing, it just tells you what it would do. If you like what it shows, just remove the word echo and run it again.
Save the code above as flopper, and then go to Terminal and type this:
chmod +x flopper # Just do this one time to make the script executable (runnable)
./flopper # Actually run it
Update:
For newer versions of ImageMagick (version 7 onwards) you do not need to write:
convert -flop
Instead you need to write:
magick -flop
So your script essentially becomes:
#!/bin/bash/
for file in *.jpg
do
magick $file -flop ${file%%.jpg}_flop.jpg
done
Note: This works when your filenames don't have spaces or newlines in them.

Running a batch with imagemagick

I need to save a bunch (several thousand) of images with imagemagick.
I'm totally new to it, and its documentation seems totally opaque and totally labyrinth. Where's the quickstart guide?
Looking at it, I think I want to use mogrify.
so I cd to my program files directory where I installed imagemagick.
I run mogrify -format png *.png as I see in various examples.
It says:
mogrify: unable to open image `fgimg\': No such file or directory # blob.c/OpenB
lob/2489.
mogrify: unable to open file `fgimg\' # png.c/ReadPNGImage/2865.
How do I instruct it to run on all images in the subdirectory \fgimg?
Thanks a lot!
The problem here is that you're hitting the limit of how much you can put on a command line. You need to split it into chunks that will fit. This should work better:
find -name '*.png' -print0 | xargs -0 -r mogrify -format png
The -print0 and -0 are used to handle spaces in filenames, and the -r means don't run mogrify if there's nothing to do.

Resources