Run optipng png optimizer on several cores - optipng_multicore.sh

So. It's a wrapper. I got bored when I have HEXA core on my server and I usually want to maximize (almost maximize) png optimization, but optipng as great tool it is - it lacks feature of running on multiple cores at the same time. So utilizing 1 of 6 of the cores in my case... led to this little implementation.
This script runs many optipng processes in unison/parallel to archieve threading-like support for optipng.
Secret lies within xargs.
Note that for now this script goes trough all the possible combinations/trials. I'm planning to change that to user defined.
It requires bash and xargs that are found from almost every Arch install. And, of course, optipng itself.
Here's the code (for you all to improve?):
#!/bin/bash
# optipng_multicore.sh
# optipng wrapper to use all the cores at maximum settings.
# Code: [email protected] Zucca@IRC (several networks)
# Licence: I guess MIT would be ok. Just mention my contact info if you want to fork/take over.
# Version 0.2.5
HELPMSG="
= optipng spawner for multiple CPU cores =
-f|--force Force overwriting files
-c|--num-cpu|-t|--threads Specify number of threads (default: automatic detection)
-h|--help Umm... It's a surprise?!?
Use '--' to stop searching switches."
# The dirty way to get CPU count (counts HT cores as two)
CPUCOUNT="$(grep -c ^processor /proc/cpuinfo)"
## Parse cli args ##
while [ "${1:0:1}" == "-" ]
do
case $1 in
-h|--help)
echo "$HELPMSG"
exit 0
-f|--force)
FORCE=true
-c|--num-cpu)
if egrep -q '^[0-9]+$' <<< "$2"
then
CPUCOUNT="$2"
else
echo '--num-cpu option must be followed by a number argument!' >&2
exit 1
fi
shift
--) # Stop searching switches
shift # break forces to exit the loop right here
# that's why we must shift here before
break
echo -e "DUDE! I don't know what to do with that switch \"$1\" of yours." >&2
exit 1
esac
shift
done
for PNGIN in "$@"
do
COUNTER=0
TMPDIR="$(mktemp -d)"
# Doing this "YO dawg" -loop is because one might want to change possible combinations
# ... and for the future development. ;)
for ZC in 1 2 3 8 9 # Compression levels
do
for ZM in {1..9}
do
for ZS in {0..3}
do
for F in {0..5}
do
for I in {0..1}
do
echo "-zc${ZC} -zm${ZM} -zs${ZS} -f${F} -i${I} -zw${ZW} -out \"${TMPDIR}/${COUNTER}.png\" \"$PNGIN\"" >> "$TMPDIR/list.txt"
let "COUNTER=$COUNTER+1" # It would be nice to have leding zeros but... meh.
done
done
done
done
done
# Start the compression
xargs -n 8 -P $CPUCOUNT -a "$TMPDIR/list.txt" optipng -quiet
# FIXME: a dirty way to remove all but the smallest size png. Maybe use find + stat
ls -Ss --block-size=1 "$TMPDIR"/*.png | head -n -1 | egrep -o "${TMPDIR}/[0-9]+\.png" | xargs rm
# Then move the rest (the only one)
let "WONBYTES=$(stat -c %s "$PNGIN")-$(stat -c %s "$TMPDIR"/*.png)"
echo "$PNGIN size reduced by $WONBYTES bytes."
test "$FORCE" == true && mv -f "$TMPDIR"/*.png "${PNGIN%.*}.png" || mv -i "$TMPDIR"/*.png "${PNGIN%.*}.png"
# Delete temp directory
rm -fr "$TMPDIR"
done
I could put this into AUR if I get enough ... um followers?
Last edited by Zucca (2013-04-13 12:08:35)

brunogm0 wrote:Nice wrapper, can you explain if xargs can auto detect  cpu cores or not ?
Afaik if you specify -P 0 (zero) xargs spans as many processes as it can. So bertter to determine cpu count by ourselves.
brunogm0 wrote:You can improve yours with my tunings and i can use your CPUCOUNT.
Thast's what the FOSS is for!
And thanks! I'll look if I can improve my script and I'll share everyting I discover/code here.
I really need to limit the number of trials on my script. -o5 level with few tweaks usually lead into desired size reduction.
I will also make my script more idiot-proof (like catching ^C and reporting possible errors).
Last edited by Zucca (2013-01-13 14:08:52)

Similar Messages

  • Will logic pro x run on my mac mini dual core intel i5 with 4gb of ram and mountain lion ?

    hi there guys,
    will logic pro x run on my mac mini dual core intel i5 with 4gb of ram and mountain lion ?
    I'm not sure if my machine is 64 bit - it is the current model base mac mini.
    Many thanks for any help you can offer !
    Simon

    SkiJumptoes is right. 4GB is not enough to comfortably run Logic X.
    Your Mac Mini will need DDR3 SODIMM RAM. That website seems incredibly steep though. I guess that's the price of finding it for you. You're better off going to any below:
    http://www.ebuyer.com/191206-kingston-4gb-ddr3-1066mhz-laptop-memory-kvr1066d3s7 -4g?utm_source=google&utm_medium=products&gclid=COqM6KzdxbgCFcfJtAodoicARg
    http://www.ballicom.co.uk/cmso4gx3m1a1600c11-corsair-value-select--memory--4-gb- -so-dimm-204pin--ddr3--1600-mhz--pc312800--cl11--15-v--unbuffered--nonecc.p87434 0.html?ref=5&gclid=CKyej_HdxbgCFQSS3godEjwAug

  • Application running in Solaris 9 container generating core files. what to do?

    My solaris 9 zone configuration in solaris 10 looks like:
    zonecfg:sms> info
    zonename: sms
    zonepath: /zone/sms
    brand: solaris9
    autoboot: true
    bootargs:
    pool:
    limitpriv: default,proc_priocntl,proc_clock_highres,proc_lock_memory,sys_time,priv_proc_priocntl,priv_sys_time,net_rawaccess,sys_ipc_config,priv_proc_lock_memory
    scheduling-class:
    ip-type: exclusive
    hostid:
    [max-shm-memory: 4G]
    [max-shm-ids: 100]
    [max-sem-ids: 100]
    fs:
      dir: /var
      special: /dev/dsk/c1t0d0s5
      raw: /dev/rdsk/c1t0d0s5
      type: ufs
      options: []
    net:
      address not specified
      physical: bge0
      defrouter not specified
    device
      match: /dev/dsk/c1t0d0s5
    device
      match: /dev/rdsk/c1t0d0s5
    device
      match: /dev/dsk/c1t0d0s6
    device
      match: /dev/rdsk/c1t0d0s6
    device
      match: /dev/dsk/c1t0d0s7
    device
      match: /dev/rdsk/c1t0d0s7
    capped-cpu:
      [ncpus: 2.00]
    capped-memory:
      physical: 4G
      [swap: 8G]
      [locked: 2G]
    attr:
      name: hostid
      type: string
      value: 84b18f64
    attr:
      name: machine
      type: string
      value: sun4u
    rctl:
      name: zone.max-sem-ids
      value: (priv=privileged,limit=100,action=deny)
    rctl:
      name: zone.max-shm-ids
      value: (priv=privileged,limit=100,action=deny)
    rctl:
      name: zone.max-shm-memory
      value: (priv=privileged,limit=4294967296,action=deny)
    rctl:
      name: zone.max-swap
      value: (priv=privileged,limit=8589934592,action=deny)
    rctl:
      name: zone.max-locked-memory
      value: (priv=privileged,limit=2147483648,action=deny)
    rctl:
      name: zone.cpu-cap
      value: (priv=privileged,limit=200,action=deny)
    Solaris 9 zone /etc/system file looks like:
    * The directive below is not applicable in the virtualized environment.
    * The directive below is not applicable in the virtualized environment.
    * The directive below is not applicable in the virtualized environment.
    * The directive below is not applicable in the virtualized environment.
    * The directive below is not applicable in the virtualized environment.
    * The directive below is not applicable in the virtualized environment.
    set noexec_user_stack=1
    set semsys:seminfo_semmni=100
    set semsys:seminfo_semmns=1024
    set semsys:seminfo_semmsl=256
    set semsys:seminfo_semvmx=32767
    set shmsys:shminfo_shmmax=4294967295
    set shmsys:shminfo_shmmin=1
    set shmsys:shminfo_shmmni=100
    set shmsys:shminfo_shmseg=10
    set rlim_fd_max=65536
    set rlim_fd_cur=60000
    * The directive below is not applicable in the virtualized environment.
    My questions are:
    1. Application running in solaris 9 container generating core files. what to do???
    2. My prstat -Z for zone shows almost 95% percent cpu usage. what to do???
    3. Kindly can share how to move solaris 9 into solaris 10 containers ??

    Based on the new questions for the same post you wrote in the other communities, some posts are removed as duplicate, here is the answer :
    For the point #3, please look on table 17-1 in the following URL :
    Zone Components - System Administration Guide: Oracle Solaris Containers-Resource Management and Oracle Solaris Zones
    You can also customize your container /etc/system file but it cannot exceeds the global zone and the zone configuration value.
    For the other point, #2, this can be complicated without a complete image of what the complete system do.
    Try fist to check if you have not a busy process in your zone, then you can check if a bottleneck exists in the I/O side. You use maybe wrong parameters, a wrong configuration or your system configuration is insufficient in term of resources.
    What I can see in the outputs that you provided is that the S9 zone uses the half of the swap space. This can impact your zone performance and I/O activity, and can have in this case a side effect on some processes. Check why your zone uses the swap and how you can remedy this.

  • When I try to upgrade and install to iOS 5.1, error message prompt "operation stop running". I have tried several time but failed. Also, would like to know why always need to have wifi access in order to upgrade the version of iPad iOS, why not 3G ?

    When I try to upgrade and install to iOS 5.1, error message prompt "operation stop running". I have tried several time but failed. Also, would like to know why always need to have wifi access in order to upgrade the version of iPad iOS, what is the purpose of 3G then? This is really nonsense using wifi + 3G iPad. need help ! Thanks.

    The file is too large to download via 3G. There is a 20MB limit with 3G. The purpose of having 3G is that you have internet access everywhere and do not need to be near a WiFi hotspot or network.
    Not every single thing that you do every single minute of the day on the iPad involves downloading files larger than 20MB. You can surf the internet all day long sitting out in a park somewhere with 3G - but not with a WiFi only iPad - unless you use a hotspot with it.
    Try turning off your firewall and anti virus software while you try to download the iOS update.

  • What is the latest Mac OS X that I can run on my 2.33 GHZ Core 2 Duo Macbook Pro?

    My MBP was running the fan almost constantly and otherwise acting odd so I decided to just refresh the installation from scratch. At that time I was running Lion 10.7.5. Before rebuilding everything with that version I want to make sure running Lion on this machine isn't contributing to my issue.
    What is the latest Mac OS X that I can run on my 2.33 GHZ Core 2 Duo Macbook Pro?
    I have every OS release since the original purchase so I can rebuild on the one that's most stable on this laptop.

    You can run Mt. Lion if you so wish:
    http://www.apple.com/osx/specs/
    If you want the most efficient OS, I would suggest Snow Leopard.
    However I suggest doing some investigation prior to installing a new OS.  First do a SMC reset:
    http://support.apple.com/kb/ht3964
    Also run an Apple Hardware Test.  Use the #2 disk on your original install disk.
    If there is no improvement, post back.
    Ciao.

  • Yesterday I installed motion 5. It crashes when creating a new project or opening a template or old project. It runs on macbook 2.1 intel core 2.16 GHz. Thanks or helpful hints.

    Yesterday I installed motion 5. It crashes when creating a new project or opening a template or old project. It runs on macbook 2.1 intel core 2.16 GHz. Thanks or helpful hints.

    It used to be in there (id 226635 is the last one with it); should I clean it up a bit and put it back with a bit more of a disclaimer?

  • Will lion run on my 2 GHz Intel Core 2 Duo

    Will Lion run on my 2 GHz Intel Core 2 Duo?

    Yes but the Lion gestures with the trackpad will not work with yours. Those require the buttonless multi-touch glass trackpad

  • Can I run Lion on on a Intel Core Duo computer?

    Can I run Lion on on a Intel Core Duo computer?
    I have on of the Intel Core Duo  macbook.
    I hope on othe apple people can answer that for me.

    This is my Macbook and I seem to be able to run a depleted Lion operating system on it
    no full screen on some applications. no response to multi swipe actions, No Air Drop. and so on and so on. Also when it loaded it stalled with no real information and i had to go to reload Lion which then instigated further download of 6 minutes to load a slightly amended copy of Lion. thought i had lost all my info but it did all reappear
    It does have Launchpad and Mission Control but i seem to have lost my Isight camera in Photo booth and Skype. this has happened occasionaly before and a reboot brings it back for a while.
    Ah well Is it time to up grade the laptop?? Do i need a laptop?? Anyway ill keep this one for a bit and see how it goes at least some of the changes work.
    Model Name:          MacBook
      Model Identifier:          MacBook3,1
      Processor Name:          Intel Core 2 Duo
      Processor Speed:          2.2 GHz
      Number of Processors:          1
      Total Number of Cores:          2
      L2 Cache:          4 MB
      Memory:          2 GB
      Bus Speed:          800 MHz
      Boot ROM Version:          MB31.008E.B02
      SMC Version (system):          1.24f3
      Serial Number (system):          W8***4
      Hardware UUID:          B618B269-D4FC-5A1D-BE2E-E8B2383FEEA4
      Sudden Motion Sensor:
      State:          Enabled
    <Edited by Host>

  • Running a single program on several clients

    Hi,
    I'm making a program which is going to be put on a server. The users will have this server mapped as a network drive (say, P:). For the user to run the program, she/he will run a bat-file (which sets 'PATH' to include JRE (which is also on the server) and starts the program with javaw).
    The program takes input from the user (both by reading from user-specified file(s) and by getting data from a JTable edited by the user), generates information in a (temp) file, may save the file, and may send the file to another server.
    Storing of files is done on each user's own computer and not on the server (specifying "C:\TEMP" places the file on the computer running the program, not on the server).
    My question is this:
    When several users run the program at the same time, how will the program act?
    What happens if a couple (or more) users try to do the same thing at the same time, i.e. access the same methods at the same time? (For example generate XML from the table or send the generated file.)
    I've tried 'playing server' by sharing my program on the internal network and running it on other computers, and it all seems to be working well.
    Is there something I should be aware of?
    Should I use Threads and/or synchronization?
    -negal

    yes, i got that. as i said, in this case you need
    locks only on the resources that multiple threads
    modify (the JTable in your case, and whatever else you
    are using).What?!?
    There is nothing in the above discussion that suggests that a client server architecture is in use.
    There is a computer A which has application code. And a computer B where the code runs. The fact that there is two computers is irrelevant to the question. From the point of view of this architecture the code just a well live on computer B. It makes no difference.
    A JTable is a GUI component. Even in a client server architecture a JTable will ALWAYS be independent for every client.
    Now the resources that a JTable displays might not be independent but nothing in the above points out that any resources, at all, are shared.
    Now if there WAS a server component then that would mean there was an application RUNNING on the server. That is not the same as the application code being stored there.
    Now there might be a shared resource in the above when the OP says "send the file to another server." But that is the only possibility of a shared component (as server application.)
    Presumably if the OP has a server application (which is NOT what is being discussed here) then they need to provide more information about that. The client, as it is, does not do anything that involves shared resources.

  • Can Tiger (OSX 10.4) run on a Macbook Pro quad core i7

    I have a Macbook Pro 2.2 GHz quad core i7.  I would like to have three partitions one for OSX 10.6, one for OXS 10.4 to run some older software and one for Windows 7.   I have these  3 partitions setup and OSX 10.6 and Windows 7 installed and working properly.  I now would like to install OSX 10.4 to the 3rd partition but can not boot to the installation disk.  I tried holding down the C key, I tried a different copy of the disk which will boot my older mac so the disk is OK.   Can this be done or is OSX 10.4 to old to run on the i7.   Is there another way I can install other then from the CD.

    Apple cautions not to install an OS earlier that what the Mac came with...
    http://support.apple.com/kb/HT2186
    http://support.apple.com/kb/HT2597
    In practice it really matters if there were Hardware changes since that model/line came with 10.4, the earliest MBP i7 I see, came with 10.6.3, so I doubt 10.4 or 10.5 will run on it.
    Is there another way I can install other then from the CD.
    If you want to try it, you'd need an older Mac that could boot from that Install Disc & your new MBP in Target mode.

  • How will Logic Pro X run with a 2006 iMac (Intel Core 2 Duo, 2.16 GHz, 4GB ram)?

    I have a 2006 iMac 2.16 GHz, 4GB ram, Intel Core 2 Duo. I am not planning on using plug-ins, I am a beginning artist and Logic Pro seems to have more than what I need. Any help would be greatly appreciated.

    Yes it will.. I would recommend you use the combination of  Snow Leopard 10.6.8 and LPv9.1.5 (or 9.1.8 if you have to..) with that particular hardware to get the best performance out of it... I would not recommend running any OS X version higher than 10.6.8 as each new version of OS X from then onwards.. placed a bigger performance hit on the hardware... and frankly, less stability with LP9.
    As to how well it will run on that hardware.. will more depend on the sort of loads you place on it.. depending on the type and content of the music you wish to compose... It will run and you should be able to create reasonable sized projects.. but again, it all depends on the plugins used.. the number of them... the number of tracks and so on... so to give a more precise answer is difficult.

  • Running 10.5.8 on Intel Core Duo, Snow Leopard disc (purchased from Apple) won't work

    I am running 10.5.8 on my iMac and want to upgrade to Lion. Was told to upgrade to Snow Leopard first. Purchased the Snow Leopard install DVD from Apple, but it begins the installation process then says CD is dirty. Hooked up an external DVD drive and tried again, got the same message. I literally unwrapped the disc and put it directly into the drive...it couldn't have gotten so scratched or dirty that it wouldn't work.
    Here is my system info:
    Model Name:          iMac
      Model Identifier:          iMac4,1
      Processor Name:          Intel Core Duo
      Processor Speed:          1.83 GHz
      Number Of Processors:          1
      Total Number Of Cores:          2
      L2 Cache:          2 MB
      Memory:          1.5 GB
    Any ideas on what I can do? I've read that there were tons of problems with this disc/upgrade...
    Thanks!

    Call the place you bought Snow Leopard from, and ask for them to replace the disk as it or your DVD drive is obviously defective.   As others have noted, you can't upgrade to Lion regardless.
    That said, before you install 10.6, be sure you really are prepared for it: https://discussions.apple.com/docs/DOC-2455   
    And if after getting a replacement 10.6 disk it fails to install, verify your PRAM battery is not over 4 years old, and that your optical drive isn't dirty by bringing it in for service.

  • Is a matching pair of Ram required to run an iMac 1.83Ghz Intel Core 2 Duo?

    I have an iMac 17" 1.83Ghz Intel Core 2 Duo with the standard 512mb ram (2x 256mb) installed. If I replace one of the memory slots with one 1gb ram stick, and leave one 256mb ram stick (1.256gb ram total), will my system run properly? Will it run at its optimal performance level? Or will Installing 2 sticks of 512mg ram perform better?
    Also, is 1gb - 1.256gb ram enough to run parallels (windows xp) smoothly?
    Thanks in advance.

    Hi Jay
    Welcome to Apple Discussions
    First use the link below:
    How to identify your iMac
    If you have a 17-inch iMac (MA710LL) Intel GMA 950 graphics processor with 64MB of DDR2 SDRAM shared with main memory then YES you need to keep the ram matched in that model.
    iMac (Early 2006), iMac (Mid 2006), iMac (17-inch Late 2006 CD): Memory Specifications

  • HT3161 I have a 27" mac running with a 3.4 ghz core i7 and 16 gigs of ram and using the latest logic. I have a composition consisting of 7 audio tracks and 4 software instruments and 4 plugins on 4 tracks so why is my CPU spiking ?

    I'm running a 27" imac with a 3.4ghz core i7 processor and 16 gb of ram.... In logic I have a project with 7 audio tracks with various plugins running and 4 software instruments which incidentally are not playing all the way through the track...my CPU spikes even if the project is paused...why is this happening on such a high end machine.....wasting my money again seems to spring to mind !!

    Did you read this support article?
    http://support.apple.com/kb/ht3161

  • Wireless Network problems after running VZ Speed Optimizer

    Good Day and thanks for reading!
    This issue may sound improbable but, please hear me out. To begin my network has 2 Windows 7 x64 PCs connected to the modem/router via Ethernet, a wireless laptop, a wireless PS3, 2 android smart phones and a tablet running on Wifi. (usually not all at the same time)
    Everything had been working properly until I recently did a clean (re)install of Windows on one of the PCs with a wired connection. After getting back to the desktop I did a couple required updates installed Norton 360 then downloaded and ran the Verizon Speed Optimizer (http://my.verizon.com/services/speedoptimizer/fios/).
    This was the first time I'd ever ran the vz speed optimizer, I only did it on a whim.. I figured it couldn't hurt. The program only took a second to complete and everything seemed normal at first; internet speeds seemed as fast as normal. 
    It wasn't until next day I noticed all the wireless devices in the house started having connectivity issues whenever that PC was running; even at idle. The PS3 would drop the PSN connection regularly and take forever to reconnect, the tablet and phones download speeds were unusable and also intermittent.  I could shut down that PC, restart the tablet/PS3/etc and have them working normally.
    After a little research I ended up re-running the optimizer program and at the end clicked 'undo settings to defaults' hoping that would resolve the issue.  Afterwards I unplugged the modem for 60 seconds hoping a reset would put everything back to normal but it hasn't..  When that PC is running, everything else on the network has constant connectivity issues.
    Is it possible the speed optimizer program did something to the wireless settings of the modem, or somehow gave that one Windows PC dominance over the network? I was under the impression the optimizer would change a couple local settings on that machine. I can't think of a reason why it would effect the entire network, (most evident on  the wireless devices).
    Any ideas or suggestions would be GREATLY appreciated.
    Solved!
    Go to Solution.

    I promised I would post a solution to this if found so..
    As I set up my wireless laptop next to the wired PC in preparation to call Verizon tech support, I remembered a handy app I had on my phone.. Wifi Analyzer.
    I checked the range of wireless signals the the app picked up and low-and-behold, there were two new wifi signals of decent strength operating in the same channel (1) that I was set up in!  (I hadn't checked this since I first set up my router over a year ago and the apartment building next door is always getting new people)
    This was totally unacceptable!  The app showed that channel 11 had only a single, very weak signal in the area and recommended I switch to that.  After logging into the router and doing so, it was as if all the wireless tech in my house was instantly given new life!  
    I could once again be downloading a game from Steam on a wired PC, steaming netflix on the wireless PS3, watching a YouTube video on my phone, all while the wireless laptop was downloading (way too many) windows updates.
    Solution:  Regularly monitor the amount of congestion in the channel your wireless is operating in. This is especially important if your reside in or near a rental/leasing property that often has people moving in and out.
    Changing the wifi channel on your router is easy, fast and not scary at all. It could save you a lot of headaches.

Maybe you are looking for

  • Displaying the content of JPanel

    hello, I have a JPanel which contains a JScrollPane displaying data from a database. I have created a JButton which permit to hide and show the content of jpanel (hide and show jscrollpane alternaly). but when I hide the content the first once I cant

  • Reporting issue (very urgent)

    Sr.No     Flt.NO     ORI- DES     Total Flts     TS OFF     FC     KC     TS Util      FC 1     IT101     BOM-BLR        20     2,680     400     2,280     2,165     230 2     IT103     BOM-BLR        20     3,216     480     2,736     2,322     245

  • Block payment term field

    Hi, we want to grey out the payment term field in the sales order screen for the end user.Please suggest what should be done Thanks AJ

  • Need help in configuring work email

    recently purchased 8310 curve. i have tried configuring using outlook web access option and outlook exchange option but some how not able to connect ot the server. have been able to configure yahoo email address. Message Edited by asv on 08-20-2009 0

  • HT4759 I lost my iPhone, please help me find it because it is not reflected on the app(find my iPhone) when I do a search on it.

    Can someone help me to retrieve my 5s with apple intelligence software,