Duplicate images after conversion

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Duplicate images after conversion

Post by mrc88 »

Hi, I have a problem with imagemagick.
Entering this command:

convert /var/www/html/wp-content/uploads/img/*.* -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680 /var/www/html/wp-content/uploads/img/*.*

I have many duplicates of the converted images.
I have no problems when a single file, the problem exists only when I have two or more files.
I have tried many and many files, I tried to insert "-duplicate 0" but the problem is the same.

Screenshots
before converter
Image

after converter
Image

image one.jpg
Image

image two.jpg
Image

image two-0.jpg
Image

image two-1.jpg
Image

image two-2.jpg
Image


How can I solve it?
Thank you.
Marco
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Duplicate images after conversion

Post by fmw42 »

You cannot use wild cards for the output when you use wild cards for the input with convert. If you want to process a whole folder or set of file, then use mogrify rather than convert. See https://imagemagick.org/Usage/basics/#mogrify It is designed for batch processing. If you do not want to do that, then you will have to write a script loop over each of your input images and use convert to process each one, one at a time.
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Re: Duplicate images after conversion

Post by mrc88 »

Thank you very much.
Now works.

One last question a bit off topic:
From the terminal I can convert all the files in the folder, if I insert the same code in a .sh file it won't work if I start it from the wordpress plugin. I mean that the whole .sh file is loaded correctly, only the "imagemagick" line is not.
Why? Problem with permissions?

Thanks for your kindness.
Marco
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Duplicate images after conversion

Post by fmw42 »

Sorry, I do not know Wordpress. So I cannot answer your question. Perhaps ask on a Wordpress forum? Just guessing, but perhaps from Wordpress, you might need put the full path to convert. Otherwise, perhaps show us your script.
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Re: Duplicate images after conversion

Post by mrc88 »

Of course, here is my script.
The "exiftool" command and the "mediafromftpcmd.php" file are executed correctly, unfortunately the "mogrify" (or "convert") no command.
Thanks anyway for your help. You're very kind.
Marco

Code: Select all

#!/bin/sh
exiftool -r -d %Y_%m_%d_%H%M%S.%%e "-filename<filemodifydate" /var/www/html/wp-content/uploads/img/
mogrify /var/www/html/wp-content/uploads/img/*.* -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680 /var/www/html/wp-content/uploads/img/*.*
/usr/bin/php /var/www/html/wp-content/plugins/media-from-ftp-add-on-cli/lib/mediafromftpcmd.php
exit	
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate images after conversion

Post by snibgo »

Your mogrify command is wrong. See http://www.imagemagick.org/script/mogrify.php . Mogrify does not take both input and output filenames. It takes one filename (with wildcards) that is for input and also, by default, for output.
snibgo's IM pages: im.snibgo.com
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Re: Duplicate images after conversion

Post by mrc88 »

the line
exiftool -r -d %Y_%m_%d_%H%M%S.%%e "-filename<filemodifydate" /var/www/html/wp-content/uploads/img/
is managed by Exiftool, not by imagemagick
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate images after conversion

Post by snibgo »

Yes, the "exiftool" line is an exiftool command.

The next line, with "mogrify", is a mogrify command, and it is wrong.
snibgo's IM pages: im.snibgo.com
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Re: Duplicate images after conversion

Post by mrc88 »

Why is it wrong?
Works properly from "Terminal"
The conversion from cmyk to rgb works, the maximum pixel size works, and I think the quality setting works.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Duplicate images after conversion

Post by fmw42 »

You cannot use wild cards for input and output in mogrify. Look at the documentation for the syntax. See my link above.

change directory to inputfolder
mogrify <processing commands only> *

That will get each image from the current directory, process it and write over it with the output. So the * means both input and output. If you want to write to another directory for the output, then create it beforehand and specify it with -path outputdirectory
mrc88
Posts: 6
Joined: 2019-04-23T10:21:07-07:00
Authentication code: 1152

Re: Duplicate images after conversion

Post by mrc88 »

I tried to insert the .sh file with the code
mogrify -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680
(also: magick mogrify -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680 )
in the folder where there are images (without inserting the directory) but it does not work.

I tried my command line from Terminal and it works.
I don't think it's the command line's fault but permission...
You don't think??
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Duplicate images after conversion

Post by fmw42 »

You have to put * at the end of your mogrify command for it to get the input images from the current directory. It will then write over those images. So be sure you have a backup.

mogrify -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680 *

Otherwise create a new directory and add -path to the command

mogrify -path newdirectory -profile /var/www/html/cmyk.icc -profile /var/www/html/srgb.icc -quality 70 -resize 680 *

Please read the page on mogrify! https://imagemagick.org/Usage/basics/#mogrify
Post Reply