Convert png picture to jpg in command line [SOLVED]

Paint programs, vector editors, 3d modelers, animation editors, etc.
Post Reply
Message
Author
User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

Convert png picture to jpg in command line [SOLVED]

#1 Post by Argolance »

Hello,
Does any very small and autonomous script exist, already present (or not!) on Puppy (as "resizepng" for example!) that would convert png pictures to jpg (something like "png2jpg")? Where could I find this?

Cordialement.
Last edited by Argolance on Wed 15 Aug 2012, 16:38, edited 1 time in total.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#2 Post by rcrsn51 »

Code: Select all

pngtopnm xxx.png | pnmtojpeg > xxx.jpg
Or as a script named "png2jpg":

Code: Select all

#!/bin/sh
pngtopnm $1 | pnmtojpeg > ${1%.*}.jpg
Or if your filenames may contain spaces:

Code: Select all

#!/bin/sh
pngtopnm "$1" | pnmtojpeg > "${1%.*}.jpg"

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#3 Post by Argolance »

Hello rcrsn51,
Thank you! :D
I know this is not the place to ask this question but:
I didn't succeed in making several commands one after the other with scrot...
Usage : scrot [OPTIONS]... [FILE]
Where FILE is the target file for the screenshot.
If FILE is not specified, a date-stamped file will be dropped in the
current directory.
See man scrot for more details
-h, --help display this help and exit
-v, --version output version information and exit
-b, --border When selecting a window, grab wm border too
-c, --count show a countdown before taking the shot
-d, --delay NUM wait NUM seconds before taking a shot
-e, --exec APP run APP on the resulting screenshot
-q, --quality NUM Image quality (1-100) high value means
high size, low compression. Default: 75.
For lossless compression formats, like png,
low quality means high compression.
-m, --multidisp For multiple heads, grab shot from each
and join them together.
-s, --select interactively choose a window or rectnagle
with the mouse
-t, --thumb NUM generate thumbnail too. NUM is the percentage
of the original size for the thumbnail to be,
or the geometry in percent, e.g. 50x60 or 80x20.

SPECIAL STRINGS
Both the --exec and filename parameters can take format specifiers
that are expanded by scrot when encountered.
There are two types of format specifier. Characters preceded by a '%'
are interpretted by strftime(2). See man strftime for examples.
These options may be used to refer to the current date and time.
The second kind are internal to scrot and are prefixed by '$'
The following specifiers are recognised:
$f image path/filename (ignored when used in the filename)
$m thumbnail path/filename
$n image name (ignored when used in the filename)
$s image size (bytes) (ignored when used in the filename)
$p image pixel size
$w image width
$h image height
$t image format
$$ prints a literal '$'
\n prints a newline (ignored when used in the filename)
Example:
scrot '%Y-%m-%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'
Creates a file called something like 2000-10-30_2560x1024_scrot.png
and moves it to your images directory.
How could this be done? i. e. get a picture, give it defined height and width in pixels then save it in a directory as jpg file, all in the same command line...
Any idea?
Thank you!

Cordialement!

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

scrot is patched by ubuntu . At least one option is not in the original source code iirc.

Jasper

#5 Post by Jasper »

Hi Argolance,

If you haven't seen PupSnap find any post by radky and click on his PupMates, signature and scroll down to PupSnap 1.8. It's superb and may be of huge interest to you.

My regards

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#6 Post by rcrsn51 »

Argolance wrote:How could this be done? i. e. get a picture, give it defined height and width in pixels then save it in a directory as jpg file, all in the same command line...
Try this

Code: Select all

#!/bin/sh
pngtopnm "$1" | pnmscale -width $2 -height $3 | pnmtojpeg > "${1%.*}.jpg"

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#7 Post by Argolance »

Hello,
@Jasper
If you haven't seen PupSnap find any post by radky and click on his PupMates, signature and scroll down to PupSnap 1.8. It's superb and may be of huge interest to you.
... Sorry but it is not what I am looking for: I made a very similar script for Toutou LINUX (French version of Puppy) and posted it in the Forum=> Easyshot

I would like a single scrot command line working quietly inside an other script.Till now, I saved the "scrot" picture somewhere then, using several different scripts, reduced, converted, renamed and moved this image to a specific directory (and this was first the reason of this thread!). But, looking at the help file of "scrot" (please see above), it seems possible to do this at one time, directly with the "scrot" options but I guess I don't know how to build this command for scrot to execute all the options inside a single line...
I think this question should/could be solved and very useful...

@rcrsn51
This is interesting because scrot can make pictures directly in pnm format. Your command line suits me and it will be enough for me!
Thank you!
Just a last question: "$1" => picture name? $2 and $3 => width/height in pixels?

Cordialement.

User avatar
stu91
Posts: 145
Joined: Mon 06 Aug 2012, 15:11
Location: England. Dpup. Dell Inspiron 1501

#8 Post by stu91 »

Hi Argolance,
I dont think you can directly specify resolution for scrots main screen capture - you need to take the main capture then scale it to size with the -t thumb nail option - then remove rm $f main capture and move thunbnail mv $m to main file name $f.
try:

Code: Select all

scrot -t 640x400 '/root/test.jpg' -e 'rm $f && mv $m $f'
or

Code: Select all

scrot -t 50%  '/root/test.jpg' -e 'rm $f && mv $m $f'

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#9 Post by Argolance »

Hello stu91,
This looks (a little bit!) like what I did, using pnm commands:

Code: Select all

	scrot 'theme_shot_tmp.pnm' -e 'mv $f /tmp/'
	pnmscale '/tmp/theme_shot_tmp.pnm' -width 600 -height 375 | pnmtojpeg  > '/tmp/theme_shot_tmp.jpg'
	mv -f /tmp/theme_shot_tmp.jpg /root/.jwm/themes/themes_pictures/"${THEME_NAME_}_perso.jpg"
Thank you very much to all of you!
This Forum is "fantastic"!

Cordialement.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#10 Post by MU »

[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#11 Post by rcrsn51 »

A GUI version of scale2pic is here.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#12 Post by Argolance »

Thanks...

Post Reply