output filtered images to new folder and rename them - imagemagick

I want to add some filters to all jpg images inside a folder using the terminal like this:
convert *.jpg -colorspace Gray -sharpen 0x4.0 {}.jpg
The above line of code works fine except one issue:
I have all images inside the folder with incrementing numbers like : 1.jpg and 2.jpg.
I want the new filtered images to go to a separate folder inside the current folder and rename them like 1-filtered.jpg and 2-filtered.jpg
How can we do that?

In ImageMagick, you can do that as follows. Assume your images are in directory test1 and you want them in an existing directory called test2 within test1. So you change directories to test1 and run:
convert *.jpg -set filename:f "%t" -sharpen 0x4 "test2/%[filename:f]-filtered.jpg"
test2 must already exist. ImageMagick will not create a new directory.
"%t" gets the name without the suffix and puts it into variable f.

Related

jpg images without extension aren't displayed

from kivy.uix.image import Image
self.img = Image(source="image") # This works when image is an PNG image
self.img = Image(source="image.jpg") # This works when image.jpg is a JPG image
self.img = Image(source="image") # This doesn't work when image is a JPG image
I need to specify images without extention for the app to be generic (working with more image types). Can I achieve it somehow?
Kivy is using "imghdr" to determine the image type here, and as a fallback it uses the file extension here.
That explains why the image loads fine when it has a file extension, even though "imghdr" can't find the file type in the file's content.
I tested on a list of JPEG files, and each time "imghdr" was able to detect the file type each time. That is done here im imghdr. Notably, "imghdr" does not consider the file extension.
$ python
>>> import os, imghdr
... for f in os.listdir('.'):
... print('%s -- %s' % (f, imghdr.what(f)))
Maybe the JPEG file is missing the "JFIF" or "Exif" string that imghdr is looking for? You could use hexedit to see if one of those string is present at Byte 6 of the image file.

Extract/Convert an (multi-file)image that converted

I have a file made with a program , an image sticker maker .
I know this program saves it's images(probably an image, a bg and a mask) into single file with extension ".adf" .
I couldn't convert the output file with image magick cause of below error :
convert: no decode delegate for this image format `output.adf' # error/constitute.c/ReadImage/532.
I don't know how this Image converted with Image magick .
it's my -list configure result :
Path: [built-in]
Name Value
-------------------------------------------------------------------------------
NAME ImageMagick
Path: configure.xml
Name Value
-------------------------------------------------------------------------------
CC vs10
COPYRIGHT Copyright (C) 1999-2011 ImageMagick Studio LLC
DELEGATES bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES OpenMP
HOST Windows
LIB_VERSION 0x671
LIB_VERSION_NUMBER 6,7,1,0
NAME ImageMagick
RELEASE_DATE 2011-07-15
VERSION 6.7.1
WEBSITE http:// www.image magick.org
I attached the file :
src.adf
* EDIT *
if I run file command on src.adf it tells :
root#MexHex-PC:# file -vv src.adf
file-5.25
magic file from /etc/magic:/usr/share/misc/magic
What's missed !?
Thanks
This src.adf looks like a very minimal & flat data file. I know nothing about Dalahoo3D and/or ArcGis products, but we can quickly extract the embedded images with python.
import struct
with open('src.adf', 'rb') as f:
# Calculate file size.
f.seek(0, 2)
total_bytes = f.tell()
# Rewind to beging.
f.seek(0)
file_cursor = f.tell()
image_cursor = 0
while file_cursor < total_bytes:
# Can for start of JPEG.
if f.read(1) == b"\xFF":
if f.read(3) == b"\xD8\xFF\xE0":
print("JPEG FOUND!")
# Backup and find the size of the image
f.seek(-8, 1)
payload_size = struct.unpack('<I', f.read(4))[0]
# Write image to disk
d_filename = 'image{0}.jpeg'.format(image_cursor)
with open(d_filename, 'wb') as d:
d.write(f.read(payload_size))
image_cursor += 1
else:
f.seek(-3, 1) # Back cursor up, and try again.
file_cursor = f.tell()
Which dumps the following three images...
I'm sure this file was made with Imagemagick. I had already seen that one would convert the file to tiff image. He told me to do this with Imagemagick but did not explain the method.
I'm guessing this is just a matter of miscommunication. It's true that ImageMagick commonly handles JPEG / TIFF formats, but not geographic information systems and/or 3D modeling. That's usually extended by a vendor -- like ArcGIS. I would bet that ImageMagick is present in the workflow of generating TIFF files, but .ADF wouldn't be supported by ImageMagick until someone writes a delegate coder.
Update
From this question, it looks like you'll need to extend ImageMagick delegates to call GDAL utilities. You'll need to update the delegates.xml file to call the correct utility.

Svg to jpg or png file using Paperclip in Rails 5.1

I've been using paperclip for a while, allowing my users to upload svg files to it. The problem here is i would like to convert that svg file into a png (or jpg, it doesnt matter). But i dont know if there is a convert_option value to transform it, or if we can do something about it.
When i run
convert file.svg file.png
in my console, i'm getting
attribute not recognized: n
attribute not recognized: u
attribute not recognized: n
attribute not recognized: u
convert: unable to open image `#': No such file or directory # error/blob.c/OpenBlob/2701.
convert: no decode delegate for this image format `' # error/constitute.c/ReadImage/504.
convert: unable to open image `#': No such file or directory # error/blob.c/OpenBlob/2701.
convert: no decode delegate for this image format `' # error/constitute.c/ReadImage/504.
I'm using macosx with imagemagick

How to instruct convert to resize only first TIFF frame if file path specified?

I tested some code which works fine:
C:\root\Dropbox\WWW\TIFF\sandbox 17:17:37,86
$c:\cygwin\bin\convert.exe gallery.tif[0] -thumbnail 300x300^ -format jpg gallery.jpg
But I want to specify full path to image and it is not works - why it is not working?
It is the same image.
c:\root\Dropbox\WWW\TIFF\sandbox\gallery.tif[0] == gallery.tif[0] - why it is not working?
C:\root\Dropbox\WWW\TIFF\sandbox 17:17:59,29
$c:\cygwin\bin\convert.exe c:\root\Dropbox\WWW\TIFF\sandbox\gallery.tif[0] -thumbnail 300x300^ -format jpg gallery.jpg
convert: must specify image size `\root\Dropbox\WWW\TIFF\sandbox\gallery.tif' # error/raw.c/ReadRAWImage/136.
convert: no images defined `gallery.jpg' # error/convert.c/ConvertImageCommand/3210.
You seem to be using Cygwin. Cygwin expects a different way to specify paths. IIRC, you should use something like:
convert.exe /cygdrive/c/root/Dropbox/WWW/TIFF/sandbox/gallery.tif[0] \
-thumbnail 300x300^ -format jpg gallery.jpg

Converting images to .xcf format

Is it possible to convert an image, or batch of images, to a .xcf or .psd file? Using ImageMagick's convert tool didn't work, but so far my attempts to look at doing this using gimp from the command line have been unsuccessful.
An answer can now be found here. Put the following code into a script.
gimp -n -i -b - <<eof (let*="" (="" (file's="" (cadr="" (file-glob="" "*.png"="" 1)))="" (filename="" "")="" (image="" 0)="" (layer="" )="" (while="" (pair?="" file's)="" (set!="" image="" (car="" (gimp-file-load="" run-noninteractive="" file's))))="" layer="" (gimp-image-merge-visible-layers="" clip-to-image)))="" filename="" (string-append="" (substring="" 0="" (-="" (string-length="" file's))="" 4))="" ".xcf"))="" (gimp-file-save="" filename)="" (gimp-image-delete="" image)="" file's="" (cdr="" (gimp-quit="" eof<="" pre="">
enter code hereIt's a script that batch converts to any file format that gimp can read. Just substitute ".xcf" on line 2 and ".png" on line 6 for whatever file formats you need

Resources