LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2017, 01:35 PM   #1
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,583
Blog Entries: 16

Rep: Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316
Imagemagick convert gave me a strange error when input and output files were not in the same directory


I wrote a shell script for a friend to scan weekly time sheets and convert them from tiff (the native format of scanimage) to jpg in order to be able to email them to her supervisor. Tiffs are huge files and gmail spits them out.

I could not get this script to work. The line it choked on was:
Code:
convert newscan.tiff Pictures/timesheets/$name.jpg
where name was "sheet-ddmmyy". I can't reproduce the exact error message, as it was all done on her computer, but it started with the standard "No such file or directory ~/Pictures/timesheets/sheet-ddmmyy" and then went on to talk about a "blob". Something like "No such file or directory @ blob.c/OpenBlob/2480".

Well, of course there's no such file! The purpose of the convert command is to create it. Googling suggested that this message is sometimes a permissions problem, but it definitely was not one in this case.

Finally after much experiment, I replaced the convert command with
Code:
convert newscan.tiff $name.jpg
mv $name.jpg Pictures/timesheets
That worked. But why did it work and the other didn't? It seems completely illogical.

Last edited by hazel; 04-18-2017 at 01:11 AM.
 
Old 04-17-2017, 02:05 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
seeing that no script is present.
Code:
userx@slackwhere⚡~/bin $convert TESTUntitled.tiff /home/userx/scripts/newjpg.jpg
 
userx@slackwhere⚡~/bin $ls /home/userx/scripts
MP3Sort                       metadata-restore-mp3s  resample-flacy-move-mp3
brackets                      newjpg.jpg             
catagorize-mp3-resample-flac  ran-case               testfunctions
fix-track-number-sniplet      resample-flacy
script might need to look like this.
Code:
#!/bin/bash

working_dir=/home/userx/bin

copy_to=/home/userx/bin

script_dir=/home/userx/scripts

while read FILENAME
do

f=$FILENAME
path=${f%/*}
xfile=${f##*/}
title=${xfile%.*}
ext=${xfile##*.}

newName="WhatEver"."jpg"

[[ "$ext" -eq 'tiff' ]] && convert "$FILENAME" "$newName" 

mv -v "$script_dir/$newName" "$copy_to"

# if you want to delete the other file remove comment. 
#BUT test this script first before putting into production. 

#rm -v "$FILENAME"

done < <(find "$working_dir" -type f -name "*.tiff")
NOT TESTED

MOD
JUST TESTED
OK I see what it is doing now that I ran my script. It is doing just like whenever I re-sample flac to mp3, it creates the new file in whatever directory my script is in.

Which requires me to move that newly created file to where I want it to be, and if I want then delete the old one - one more line of code is needed.


I changed that script to reflect same.

output
Code:
userx@slackwhere⚡~/scripts $./convert-tiff
'/home/userx/scripts/WhatEver.jpg' -> '/home/userx/bin/WhatEver.jpg'


userx@slackwhere⚡~/scripts $ls ~/bin
C-files  TESTUntitled.tiff  WhatEver.jpg

Last edited by BW-userx; 04-17-2017 at 02:37 PM.
 
Old 04-18-2017, 01:10 AM   #3
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,583

Original Poster
Blog Entries: 16

Rep: Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316
Yes, I also found that if I didn't give a pathname for the new file, it was created locally without problems. But what I would like to know is why giving a full pathname causes convert to spit out this error. I don't know of any other command that makes a distinction between a local filename and a pathname when it comes to arguments.

My script originally ran:
Code:
# Script to scan timesheets easily and output them in jpg format
#! /bin/bash

if [ $# -eq 0 ]; then
echo "No date given! Please give date in the format ddmmyy"
exit 1 
fi
date=$1
name=sheet-$date
name="~/Pictures/timesheets/$name"
echo "Beginning scan now..."
scanimage --format=tiff --mode Gray --resolution=650  -x 215 -y 297 > newscan.tiff
echo "Scan completed. Converting image
convert newscan.tiff $name.jpg
echo "Image is stored in $name"
exit 0
Now I have removed the line converting $name into a pathname and added a line at the end to copy $name.jpg to ~/Pictures/timesheets and that works.

Last edited by hazel; 04-18-2017 at 01:27 AM.
 
Old 04-18-2017, 08:56 AM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by hazel View Post
Yes, I also found that if I didn't give a pathname for the new file, it was created locally without problems. But what I would like to know is why giving a full pathname causes convert to spit out this error. I don't know of any other command that makes a distinction between a local filename and a pathname when it comes to arguments.

My script originally ran:
Code:
# Script to scan timesheets easily and output them in jpg format
#! /bin/bash

if [ $# -eq 0 ]; then
echo "No date given! Please give date in the format ddmmyy"
exit 1 
fi
date=$1
name=sheet-$date
name="~/Pictures/timesheets/$name"
echo "Beginning scan now..."
scanimage --format=tiff --mode Gray --resolution=650  -x 215 -y 297 > newscan.tiff
echo "Scan completed. Converting image
convert newscan.tiff $name.jpg
echo "Image is stored in $name"
exit 0
Now I have removed the line converting $name into a pathname and added a line at the end to copy $name.jpg to ~/Pictures/timesheets and that works.
I'd need test data to see what it is doing and try to figure it out.

as far as it not using a path to given in a script, I'd gander that it because of the shell - or a sub shell that is created within the script itself.

As I am taking from my experience with flac to mp3 scripts. when I first started I wrote the script it was perfect. or so I thought and I was running it for hours then went to check it only to find no mp3 being where they where suppose to me.

Up on investigation I seen that they were being created in the same directory as my script is in. SO instead of reading everything that even might suggest the why - I just recalibrate my brain and conformed to what it was doing instead and rewrote my script to just move the new file to where I wanted it to be instead.

Ti give it a little more thought.

When I did it on the command line

Code:
convert file.tiff /home/somewhere/else/NewFIle.tiff
that worked. then I ran that script I wrote sing the same method and it did not work. that is when I discovered where it was creating the new file.

IF IT IS still this error or something similar

Code:
@ blob.c/OpenBlob/2480".
look at the output -- spaces - it got spaces and only one " quote at the right side of it.

that is your original file name gotten off a variable yes?

try quoting your variables and see if that holds things together.

even though I only see these (so far) that is not quoted in your script.
Code:
convert newscan.tiff $name.jpg
name=sheet-$date
maybe
Code:
name="sheet-$date"
convert newscan.tiff "$name"."jpg"
even this.
Code:
name="sheet"-"$date"
that is how I put together my new name for mp3's
Code:
NewName="$title"."mp3"
where yous would be like wise only using a var on the right side.

that way if the title is off the MetaTag or file name even and has spaces in it like this.
Code:
I got spaces in my file name
writing it like this.
Code:
NewName="$title"."mp3"

#if I echo $NewFile 
#that is what I get. 

"I got spaces in my file name.mp3"
so this should be valid.

Code:
name="sheet"-"$date"
where the - hyphen is used in yours, and I use the . period between the two separate parts (left side - right side) of the file name.

because that gets you your entire file name if it has spaces in that original file name then it needs to be quoted.


If that still gives you errors after you try that then I'd suggest looking at the file names and how your getting them in to your script

Code:
 name-ddmmyy

sheet-050417.tiff
is that what they actually look like?

I am trying to set up a test file and run your script right now -- getting EOF errors and this
Code:
userx@voider⚡~/scripts $./convert-tiff2-jpg 111213
Beginning scan now...
scanimage: unrecognized option '--resolution=650'
./convert-tiff2-jpg: line 15: unexpected EOF while looking for matching `"'
./convert-tiff2-jpg: line 17: syntax error: unexpected end of file
gray scale GIMP image named sheet-111213.tiff

Last edited by BW-userx; 04-18-2017 at 09:30 AM.
 
Old 04-18-2017, 09:39 AM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
OK going into inveta-ga-tory mode
Code:
userx@slackwhere⚡~/scripts $./convert-tiff2-jpg 111213
/home/userx/Pictures/sheet-111213 - for picture
Beginning scan now...
scanimage: sane_start: Invalid argument
Scan completed. Converting image
convert: Cannot read TIFF header. `newscan.tiff' @ error/tiff.c/TIFFErrors/561.
convert: no images defined `/home/userx/Pictures/sheet-111213.jpg' @ error/convert.c/ConvertImageCommand/3257.
Image is stored in /home/userx/Pictures/sheet-111213
Not actually getting that NEW Image either.
Code:
userx@slackwhere⚡~/scripts $ls ~/Pictures/sheet*
/home/userx/Pictures/sheet-111213.tiff
only the original one is there.

OK I googled scanimage -- it looks like that is to hook up to a scanner.
https://wiki.archlinux.org/index.php/SANE
Code:
If the scanning fails with the message scanimage: sane_start: 
Invalid argument you may need to specify the device.
that explains this error
Code:
convert: Cannot read TIFF header. `newscan.tiff' @ error/tiff.c/TIFFErrors/561.
*************************************************************************LOOK HERE*************

******************************************NOW I THINK I GOT A HANDLE ON IT ********



this
Code:
"No such file or directory ~/Pictures/timesheets/sheet-ddmmyy" 
and then went on to talk about a "blob". 
Something like "No such file or directory @ blob.c/OpenBlob/2480".
is because of this
Code:
name="~/Pictures/timesheets/$name"

echo "$name <- name is"

take away the quotes.
make it

name=~/Pictures/timesheets/$name

then 
echo "name is --> $name"
SO that the tilly mark expands fully to an absolute path.

echo it before and after you remove the " quotes "
that will show you whats going on.


lets see
"Now I have removed the line converting $name into a pathname and added a line at the end to copy $name.jpg to ~/Pictures/timesheets and that works."

as stated your
  1. "~/Pictues/timesheets/image.ext" - quotes need to be removed to expand to absolute path.

OK I hope I am not going into OVER KILL here --

I think all it is you're referring to is how your path is set to get convert to see it . that'd be the quote issue.
I think that is it. Though that spaces in a file name thing too remember quotes are your variables.
exception to the rule is when using relative path ~/ do not quote it

I think I have wrote enough.. (O to the over kill)

Last edited by BW-userx; 04-18-2017 at 10:28 AM.
 
Old 04-18-2017, 11:53 AM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,426
Blog Entries: 10

Rep: Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249
Quote:
Originally Posted by hazel View Post
I could not get this script to work. The line it choked on was:
Code:
convert newscan.tiff Pictures/timesheets/$name.jpg
where name was "sheet-ddmmyy".
try to put the path in double quotes:
Code:
convert newscan.tiff "Pictures/timesheets/$name.jpg"
and make sure it actually ends in .jpg (if you want a jpg).
 
Old 04-18-2017, 12:04 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by ondoho View Post
try to put the path in double quotes:
Code:
convert newscan.tiff "Pictures/timesheets/$name.jpg"
and make sure it actually ends in .jpg (if you want a jpg).
That logic is ok, somewhat, the issue is if one does that with the script, it will not have absolute path to where to put it.

if script is a different directory or same dir. it will not have the proper path.
Code:
userx@slackwhere⚡~/scripts $./convert-tiff2-jpg 111213
Pictures/sheet-111213.tiff - for picture
Beginning scan now...
Scan completed. Converting image
convert: Cannot read TIFF header. `newscan.tiff' @ error/tiff.c/TIFFErrors/561.
convert: no images defined `Pictures/sheet-111213.tiff.jpg' @ error/convert.c/ConvertImageCommand/3257.
Image is stored in Pictures/sheet-111213.tiff
there is no such address
(in lue of me actually creating a sub-dir which is not necessary for this example. )

Code:
Image is stored in Pictures/sheet-111213.tiff
Is non existent.

It was his "~/Pictures/timesheets/$file" the quotes.

Last edited by BW-userx; 04-18-2017 at 12:05 PM.
 
Old 05-02-2017, 04:59 AM   #8
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,583

Original Poster
Blog Entries: 16

Rep: Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316
Thanks, BW! I finally got to test this on my friend's computer (sorry for the delay). It's not the quotes or their absence that matters; it's the fact that I didn't give a complete path. I knew my friend would be working in her home directory, so I just said Pictures/timesheets. If I put /home/<username>/Pictures/timesheets, then it works.
 
Old 05-02-2017, 09:23 AM   #9
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by hazel View Post
Thanks, BW! I finally got to test this on my friend's computer (sorry for the delay). It's not the quotes or their absence that matters; it's the fact that I didn't give a complete path. I knew my friend would be working in her home directory, so I just said Pictures/timesheets. If I put /home/<username>/Pictures/timesheets, then it works.
AH the Ole' absolute path phenomenon ..

glad you got to actually, wait..

take a look at this. now that you explained your discovery to me.
Code:
#!/bin/bash

name="/home/$USER/Pictures"

list=$( ls "$name")

echo "$list"
see what you can do with that.

Last edited by BW-userx; 05-02-2017 at 09:24 AM.
 
Old 05-02-2017, 11:41 AM   #10
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 5,583

Original Poster
Blog Entries: 16

Rep: Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316Reputation: 3316
No problem. It works with the absolute path that you give and also with the relative path "Pictures". But seemingly the "convert" command can't do that.
 
Old 05-03-2017, 12:46 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,426
Blog Entries: 10

Rep: Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249Reputation: 5249
i just tried this on a .tiff file created with gimp, and it works, with relative path.
no output, command succesful.
(in my case name="Downloads/some")
Quote:
Originally Posted by hazel View Post
Code:
convert newscan.tiff $name.jpg
so i'm wondering...

a) version? i have
Code:
convert --version
Version: ImageMagick 6.9.8-4 Q16 x86_64 2017-04-27 http://www.imagemagick.org
b) shell? i use
Code:
bash --version
GNU bash, version 4.4.12(1)-release (x86_64-unknown-linux-gnu)
c) maybe convert thinks that the relative path is some option? maybe it has an option like '--', saying: everything after this is not a command line argument?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] failed to open div directory Input/output error ? Carl_cj Slackware 3 08-23-2016 11:52 PM
Solved: Question about ImageMagick's convert utility and high quality output Dogs Linux - Software 6 06-25-2011 04:40 PM
cannot remove `<directory>': Input/output error Linux.Girl Linux - General 6 09-15-2010 06:11 AM
[SOLVED] Using convert from imagemagick package to convert multiple jpg files janis_169 Linux - Newbie 5 07-18-2010 04:22 PM
ls: reading directory .: Input/output error when copying data to new drive abefroman Linux - Software 7 03-13-2008 07:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration