Page 1 of 1

Duplicate images after conversion

Posted: 2019-04-23T10:44:58-07:00
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

Re: Duplicate images after conversion

Posted: 2019-04-23T11:12:43-07:00
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.

Re: Duplicate images after conversion

Posted: 2019-04-23T11:45:34-07:00
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

Re: Duplicate images after conversion

Posted: 2019-04-23T11:58:52-07:00
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.

Re: Duplicate images after conversion

Posted: 2019-04-24T02:59:29-07:00
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	

Re: Duplicate images after conversion

Posted: 2019-04-24T05:33:52-07:00
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.

Re: Duplicate images after conversion

Posted: 2019-04-24T06:26:43-07:00
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

Re: Duplicate images after conversion

Posted: 2019-04-24T06:59:39-07:00
by snibgo
Yes, the "exiftool" line is an exiftool command.

The next line, with "mogrify", is a mogrify command, and it is wrong.

Re: Duplicate images after conversion

Posted: 2019-04-24T07:20:07-07:00
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.

Re: Duplicate images after conversion

Posted: 2019-04-24T09:20:31-07:00
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

Re: Duplicate images after conversion

Posted: 2019-04-24T10:36:23-07:00
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??

Re: Duplicate images after conversion

Posted: 2019-04-24T12:42:29-07:00
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