Weird "border" with jpegtran when rotating an image - libjpeg-turbo

I'm using jpegtran to rotate my images, but it seems to be doing some weird stuff.
The same code/logic worked on my other server. Here is a test case I've done:
test.jpg is the original image, then I run:
jpegtran -rotate 90 test1.jpg > test2.jpg.tmp
mv test2.jpg.tmp test2.jpg
jpegtran -rotate 90 test2.jpg > test3.jpg.tmp
mv test3.jpg.tmp test3.jpg
test.jpg:
test2.jpg
test3.jpg:
As you should be able to see, there are weird borders on it (almost like shadows on another part of the image):
What would cause this, and how can I get around it?
The OLD server shows:
jpegtran -v
libjpeg-turbo version 1.2.1 (build 20131209)
Copyright (C) 1991-2010 Thomas G. Lane, Guido Vollbeding
Copyright (C) 1999-2006 MIYASAKA Masaru
Copyright (C) 2009 Pierre Ossman for Cendio AB
Copyright (C) 2009-2012 D. R. Commander
Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)
Emulating The Independent JPEG Group's libjpeg, version 6b 27-Mar-1998
...and the NEW server shows:
jpegtran -v
Independent JPEG Group's JPEGTRAN, version 9b 17-Jan-2016
Copyright (C) 2016, Thomas G. Lane, Guido Vollbeding

Typically, no sooner had I written the question out and posted it, I found the solution :)
http://www.imagemagick.org/discourse-server/viewtopic.php?t=21341#p87099
Basically, to add "-trim" to the command - so it looks like:
jpegtran -rotate 90 -trim test1.jpg > test2.jpg.tmp
mv test2.jpg.tmp test2.jpg
jpegtran -rotate 90 -trim test2.jpg > test3.jpg.tmp
mv test3.jpg.tmp test3.jpg
I've just tried this out, and it works as expected :) Thought I would post it here in case anyone else comes across this!

Related

What do device (character special) file sizes mean?

Using ls -l normally results in a long listing that includes the file size...
-rw-r--r--# 1 user1 staff 881344 Sep 1 15:35 someFile.png
On macOS 10.13.5, and Ubuntu 20.04, character special (device) file sizes are very different...
crw------- 1 root wheel 31, 0 Aug 30 16:11 autofs
In this case, what does the "31, 0" mean?
what does the "31, 0" mean?
It's the major/minor numbers of character device.
See these:
https://unix.stackexchange.com/questions/97676/how-to-find-the-driver-module-associated-with-a-device-on-linux
https://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lgdd/lgdd_c_udev.html
Read carefully the documentation of ls(1) then about inode(7)
31 is a major device number, 0 is a minor device number.
Remember that ls(1) would use stat(2) (you might check using strace(1)...), so read Advanced Linux Programming then syscalls(2)
Sometimes, ls might be some shell alias or function. So read documentation of GNU bash. Try also /bin/ls --help
On GNU Linux, read documentation of coreutils. And it is free software, you could download and study its source code !
On MacOSX, the operating system kernel might have different system calls.
Be however aware of udev (on Linux).

bash redirection get err: bad file descriptor and file still open, why?

when I run a simple cmd in bash, I got:
$echo 12312> aaa.txt
-bash: 12312: Bad file descriptor
$lsof aaa.txt
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 20647 root 4r REG 8,1 0 1409118 aaa.txt
$bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$uname -a
Linux node39 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
is a bug here? I'm not familiar with the bash source code, but I want to
know why. So please give me some tips,best wish to you.
edit:
thx to answer my question, but I really want to know why aaa.txt still opened by
bash after error happend.
spaces - bash is very specific about spaces
echo 1234 > output.txt
int the above example 1234 in written to output.txt using redirection operator >
on the other hand if you omit the spaces
echo 1234> output.txt
redirection operator will treat 1234 as "file descriptor number"

How to create a custom Oracle Linux 7u2 iso image

I have been using a some proven steps to create my own Oracle Linux 6uX ISO images with a custom kickstart script for a long time. What i basically do is mount the iso-image using hdiutil, copy the contents to a working folder, make the modifications and create an iso using makeiso (cdrutils).
Details have been described here; http://www.reddipped.com/2015/12/virtualbox-soa-bpm-osb-bam-33-minutes/
I just made my first attempts to create a custom Oracle Linux 7u2 ISO images, but miserably failed till now.
First opening the image using hdiutil gives and 'hdiutil: attach failed - no mountable file systems'. Instead i used Keka to extract the contents of the iso.
Modified the contents of the extracted iso-image;
Removing /isolinux/boot.cat,
Adding a new ks-bd.ks
Adding a menu item to the isolinux.cfg to be able to start installation using the kickstart file
label linux_basicserver_silent\
menu label ^Install basic server silent\
menu default\
kernel vmlinuz\
append initrd=initrd.img ks=cdrom:\/ks-bd.ks\
Then created an iso again;
## Make isolinux.bin writable
chmod u+w V100082-01U/isolinux/isolinux.bin
# Build the V100082-01Uiso
cdrtools/cdrtools-*/mkisofs/OBJ/i386-darwin-clang/mkisofs -r -J -T -o V100082-01U.iso -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R \
-m TRANS.TBL -v -V Oracle\ Linux\ 7.2 ./V100082-01U
After mounting the iso image and selecting the 'linux_basicserver_silent' installation option the installation seems to stall on the message 'Starting automated install'
When selecting a standard interactive installation in the installation menu the installation also freezes with the latest step 'Reached target Basic System'
After some minutes the same error 'dracut-initqueue timeout' is repeatedly shown .
Any hints how to fix this?
-- Update 10/27/2016 --
When comparing the orignal iso with the created iso using mkisofs there are no substantial differences, i think..
Original
./isoinfo -d -i V100082-01.iso
CD-ROM is in ISO 9660 format
System id: LINUX
Volume id: OL-7.2 Server.x86_64
Volume set id:
Publisher id:
Data preparer id:
Application id: GENISOIMAGE ISO 9660/HFS FILESYSTEM CREATOR (C) 1993 E.YOUNGDALE (C) 1997-2006 J.PEARSON/J.SCHILLING (C) 2006-2007 CDRKIT TEAM
Copyright File id:
Abstract File id:
Bibliographic File id:
Volume set size is: 1
Volume set sequence number is: 1
Logical block size is: 2048
Volume size is: 2178717
El Torito VD version 1 found, boot catalog is in sector 701
Joliet with UCS level 3 found.
SUSP signatures version 1 found
Rock Ridge signatures version 1 found
Rock Ridge id 'RRIP_1991A'
Eltorito validation header:
Hid 1
Arch 0 (x86)
ID ''
Cksum AA 55 OK
Key 55 AA
Eltorito defaultboot header:
Bootid 88 (bootable)
Boot media 0 (No Emulation Boot)
Load segment 0
Sys type 0
Nsect 4
Bootoff EFE 3838
Rebuild
./isoinfo -d -i V100082-01U.iso
CD-ROM is in ISO 9660 format
System id: Mac OS X
Volume id: Oracle Linux 7.2
Volume set id:
Publisher id:
Data preparer id:
Application id: MKISOFS ISO9660/HFS/UDF FILESYSTEM BUILDER & CDRECORD CD/DVD/BluRay CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING
Copyright File id:
Abstract File id:
Bibliographic File id:
Volume set size is: 1
Volume set sequence number is: 1
Logical block size is: 2048
Volume size is: 2251903
El Torito VD version 1 found, boot catalog is in sector 718
Joliet with UCS level 3 found.
SUSP signatures version 1 found
Rock Ridge signatures version 1 found
Rock Ridge id 'RRIP_1991A'
Eltorito validation header:
Hid 1
Arch 0 (x86)
ID ''
Cksum AA 55 OK
Key 55 AA
Eltorito defaultboot header:
Bootid 88 (bootable)
Boot media 0 (No Emulation Boot)
Load segment 0
Sys type 0
Nsect 4
Bootoff 2CF 719
Instead of using 7zip, use the cdrtool utility isoinfo to extract the original iso image.
mkdir V100082-01U
cd V100082-01U
isoinfo -R -X -i ../V100082-01.iso
Then modify the image and rebuild using mkisofs
## Make isolinux.bin writable
chmod u+w work/isolinux/isolinux.bin
# Build the V100082-01Uiso
cdrtools/cdrtools-*/mkisofs/OBJ/i386-darwin-clang/mkisofs -r -J -T -o V100082-01U2.iso -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -sysid LINUX \
-m TRANS.TBL -v -V OL-7.2\ Server.x86_64 ./work

Image magick: takes too much time at linux server

I am facing an issue with time taken by imagemagic to execute the commands on my server. I also tried to make thread control from 20(default) to 1 but, no improvements.
Here are some of the commands we fire and time took for them on server. Is there any way to reduce this execution time?
/usr/bin/convert source1.jpeg -resize 4518x3013! output.png
real 0m13.150s
user 0m18.320s
sys 0m2.029s
/usr/bin/convert output.png -crop 2408x3010+1053+0 +repage cropped.png
real 0m5.978s
user 0m5.043s
sys 0m0.881s
/usr/bin/convert destination.png -draw image over 564,564+2408+3010 'cropped.png' output.png
real 0m10.085s
user 0m11.160s
sys 0m1.710s
Updated Information
identify -version command output:
Version: ImageMagick 6.8.9-1 Q16 x86_64 2014-08-16 http://www.imagemagick.org
Copyright: Copyright ( c ) 1999-2014 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib freetype gslib jng jpeg png ps tiff zlib
Server configuration:
OS version is centos 6
RAM 32GB
source1.jpeg(link)
First command executed with -bench 5 and returned below output.
Performance[1]: 5i 0.095ips 1.000e 90.970u 0:52.550
Performance[2]: 5i 0.104ips 0.522e 92.310u 0:48.110
Performance[3]: 5i 0.090ips 0.485e 93.420u 0:55.770
Performance[4]: 5i 0.086ips 0.474e 91.180u 0:58.230
Performance[5]: 5i 0.091ips 0.488e 94.850u 0:55.030
Thanks,
Sagar
Does this get you any faster?
convert input.png -quality 80% -resize 4518x3013! \
\( +clone -crop 2408x3010+1053+0 +repage \) \
-geometry +564+564 -composite output.png
For really fast PNG writing, use -quality 10 for drawings, -quality 11 for photos. This should cut your PNG-writing time by a factor of five.
The "quality" number doesn't affect image quality when writing a PNG. It only affects the compression effectiveness.

No output file from GhostScript PDF to PNG conversion

I have a two-page PDF I'm trying to convert to a PNG file. When I run:
gs -sDevice=pngalpha -o=gs-output-%d.png -r400 test1-0.pdf
I get:
GPL Ghostscript 9.07 (2013-02-14)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
%%BoundingBox: 35 35 577 757
%%HiResBoundingBox: 35.910001 35.910001 576.090022 756.090029
Page 2
%%BoundingBox: 35 35 577 757
%%HiResBoundingBox: 35.910001 35.910001 576.090022 756.090029
And then... nothing. No output files at all. Where am I going wrong?
You're so close you'll be mad ;-)
After a bit of manpage reading here's what worked for me:
gs -sDEVICE=pngalpha -ogs-output-%d.png -r400 test1-0.pdf
i.e. DEVICE instead of Device, and -o instead of -o=
In case it matters, my gs version is:
GPL Ghostscript 9.05 (2012-02-08)
try this which works perfectly with me and it get a very good results:
-sDEVICE=pngalpha -o "$OUTPUTIMAGEFILE" -dFirstPage=1 -dLastPage=2 -dNOPAUSE -dGraphicsAlphaBits=4 -dTextAlphaBits=4 "$INPUTPDFFILE"
However i guess that using -r400 is for JPEG images not PNGS

Resources