≡ Menu

Color Profiles and PDF to JPEG conversion

Again, just documenting some code for myself in case I find myself in this situation 10 years from now, and happen to be googling my blog for how to convert a PDF to a JPG/JPEG/anything really.

Let’s start off where this ordeal started… with this simple line of code:

convert source.pdf output.jpg

Jam that into a php exec statement, and you got yourself some basic PDF to jpg conversion going on… However, there will be some issues. The first one I ran into was quality (okay, so honestly the first one was the mistake of trying to use Imagick() object in php and assuming it had all the power easily accessible that existing in the command line version. It doesn’t as far as I can tell). Quality was easy enough to fix. The setting that made the difference for me was density:

convert -density 300 source.pdf output.jpg

That worked great… Until the client uploaded a PDF they had cropped in Adobe Acrobat. Strangely, when being converted using imagemagick, it was still showing white where the client had cropped. Rather than explain to the client how PDF’s have a trimbox, cropbox, bleedbox, and artbox that can all be “cropped”, I decided the best course of action was to modify imagemagick to us the cropbox instead of the trimbox:

convert -define pdf:use-cropbox=true -density 300 source.pdf output.jpg

And, again, the people rejoiced… Until the client manged to find a way to really stump me. They uploaded a pdf that contained a particular shade of green. This green went from being a nice, tree like green, to a insanely bright neon green when converted from a PDF to a JPG. I knew this was most likely a color profile issue… which in the past has always proved to be a problem for me.

Color profiles have this fun way of not always behaving the way you want them to. I tried various things to get the color profiles to behave consistently upon conversion, but no matter what I did, nothing seemed to work in all cases of conversion. So got a little more creative… I decided to try some inbetween conversions… I ended up finding something that worked by sending it through a post script (PS) file. Here’s the final 2 lines I’m now using:

pdftops -paper letter -expand source.pdf inbetween.ps
convert -density 300 inbetween.ps output.jpg

pdftops handles the cropbox on it’s own, so no need for those flags anymore. I’m not sure the density line is needed, but I left it in anyway.



{ 1 comment }

MySQL SSL Setup Debugging

For my own sanity, I’m writing down the steps I took to get SSL working between 2 servers today. I ran into some frustration following the step-by-step instructions on both mysql.com as well as on 1 or two other websites on the web. To add to the fun, it seems sometimes I would get different, no descriptive, errors such as:

  • ERROR 2026 (HY000): SSL connection error (no additional details)
  • ERROR 2026 (HY000): SSL connection error: Unable to get certificate
  • ERROR 2026 (HY000): SSL connection error: protocol version mismatch

So here is what I did, step by step, with multiple test points…

On The MYSQL SERVER  that I wanted to connect to, I logged in and created a self signing Certificate Authority (CA) and then used that to sign a key for my mysql server. The commands looked like this:

openssl genrsa 1024 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca-cert.pem

openssl req -newkey rsa:1024 -days 3600 -nodes -keyout server-key.pem -out server-req.pem
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem

You’ll note that I used 1024 for my key instead of 2048. While 2048 would be more secure, and is what is provided in the example here, it causes my version of OpenSSL to generate in a slightly weird format that the mysql client doesn’t seem to like in some cases. A number of example online said there was a simple work around involving adding “RSA” to the header and footer of the keys, but no matter what I seemed to do, this never worked for me… so I just lowered the key strength to 1024 to get it to generate it the old way. There was also a suggestion to merge the server and client certs into one “CA”… but I didn’t like that either… in fact… I didn’t want a Client cert if if I could avoid it… as I wasn’t authenticating against it… I just wanted the SSL tunnel.

Once I had my certs created, I added these 3 lines to my.cnf. In theory I could have put them in the startup command for the server, but this was the better long term solution:


Note: when I created all my certs above, I was in the folder /etc/mysql/ (in case you didn’t guess that already).

At this point, I restarted the mysql server and ran the following query on it:

show variables like “%ssl%”;

The server came back and would say that it “have_ssl” and “have_openssl” along with the paths to the certs I just loaded in. This was a good sign.

I think modified one of my users to only allow connections using SSL:

grant usage on *.* to example_user require ssl;

I than began testing from client devices. The first stop was the mysql workbench for windows. I loaded it up and tried to log in, and on the first try it failed (this I took to be a good sign, as I hadn’t told it anything about the SSL). I then grabbed the ca-cert.pem file I created on my server, and brought it over to my client box. I then told mysql workbench to use this file for the CA. You’ll note I DID NOT specify a client key or certificate for this. I then tried to connect, and wha-la, it let me in.

To confirm I was in fact transmitting over SSL at this point, I ran this query:

show status like ‘Ssl_cipher’;

and then insured it came back with a value (if it’s blank, your NOT connected over SSL)

I then moved on to my second client, which a LAMP setup. I tried connecting using phpmyadmin, and of course, it failed again as I had told it nothing about the certificate authority. So again, I copied the file over, this time adding the following to my my.cnf:


I first tested with my mysql client on the machine and it worked great. I did run into a little trouble with phpmyadmin, but I found the connect lines in my config file and basically added this one line before the connection was made, but after the init:

mysqli_ssl_set ($link , NULL , NULL , “/path/to/ca-cert.pem” ,NULL , NULL );

I think this may not have been needed if my version of phpmyadmin had been newer… but not sure. (I was in 3.4.5 at the time, the documentation I was reading would have been for 4.2.7).

Regardless, when I signed off for the night, all my mysql connections that I cared about between my older “clients” and my new mysql server were running over SSL. Tomorrow, I hope to setup some replication between servers over SSL. This may require that I create a client certificate, but until then, I’m happy to not have needed one.






A Culture of Pressure

The USA has turned into a culture of pressure. We never “ease up”. We are always “connected”. Etc.

I’m sure I’m one of the worst at this… between my job, my email, and my family, there’s barely enough time to check out the latest humble bundle.

And when I do, I feel guilty, for not doing other things that need doing.

And there is always something that needs doing.

The bible says we should have a day of rest, and up until the last 20 to 30 years, history seems to agree.

I feel like if there was some way to force a “Sunday” on everyone again, or at least get culture to really allow it, that we might see a lot of problems in our world vanish.

Maybe less students and adults snapping on Mondays…

Maybe less people suffering from anxiety.

Maybe a reduction a people addicted to drugs to help them unwind.

I’m sure this has all been said before… but it seems Christmas is a good time to mention it again.

Jesus wasn’t born in the middle of a busy city. He was born pretty much alone with his family (until the visitors started to show up). Different.

Maybe it’s time to reflect both on the peace that the one baby can bring us, and start making some changes in 2014 as a culture…

I guess that starts with changing myself first.


Bitcoin as a Government Currency

I was thinking today about Bitcoin as a government currency. Particularly, when it comes to using it as a government currency.

I think, if I was starting a new country, or looking to replace my countries currency… I would use something based on either Bitcoin or Litecoin. I’ll call it GovCoin for the sake of this blog post.

Here’s my 3 biggest reasons:

No Need For A FED – 

The currency would be self regulated in the same way Bitcoin is. The downside to this is the same downside you have to any currency that can’t be manipulated: you can’t stop panics or bubbles. But I’ll take panics and bubbles any day over having my money easily manipulated by the government.

No Need For The IRS, or Tax Season –

The one change I would make to GovCoin is how the transactions work. I would set it up so that on every transactions, either a fix feed or a percentage was taken out of the transaction. This would basically amount to a sales tax, but done on every transaction, similar to how Visa does discount rates. Every citizen would have their own “pay in” ID that must be included with the transaction that is assigned they are issued a wallet. This would make it possible track how much you’ve paid in easily, either for refund purposes (tax-exempt organizations), or simply for your own reporting. The downside to this is the damage to free trade caused by imposing a transaction tax… but I believe the costs savings of not really needing an IRS could more than make up for it.

The other catch 22… Dealing with other currencies in your country. The only real solution to this problem is to not allow business to be transacted in other currencies… I’m okay with that… There will be international companies that are able to get around taxes by doing things in other currencies… I’m okay with that. As long as they are forced to pay their employees in our country in bitcoin, and all the stores online and off, require govcoin…  If it’s an international transaction, then there would probably need to be some sort of “flat govcoin tax” for bringing it into the country (like reverse postage).

Mining To Balance the Economy

I would use mining to help keep the classes balanced more than they are now. I would look at possibly making mining exponentially harder, the more you tried to do it as a pool or individual… Thus allowing the automated distribution of wealth (lottery) to be equal among the citizens… Maybe even making it somewhat based on how many transactions (or better, how much) you engaged in (inversely)…. This would somewhat create an automated redistribution of wealth… As the richest people in the country would no longer find it worth while to mine (most likely, as their odds would be hurt by the amount of the transactions they engage in), and the poorest people could mine to possibly collect a ‘minimum wage’. Don’t get me wrong… it’s tricky… and you don’t want everyone simply relying on generating currency (that wouldn’t work)… But it’s a more “practical” way to hand out money to people than say… straight up hand outs or subsisdies…. At least this way, if they simply take the money and go and spend it like mad, they have less a chance of getting more free money… But if it works, you’ve pretty much eliminated the need for government programs that are simply there to hand out money. (You might still need some public education programs like… public education… might… being the keyword).

I’m not sure it would work… but… If I had a couple billion dollars and some land to try it out on… It would be a fun experiment… Wonder if a commune could pull it off legally inside state borders.



Christmas Is Coming

It has been awhile since I have taken the time to write here. Much has happened over the summer, most of which you could label as “busy”.

I haven’t given up on my home automation dreams, in fact, my latest improvement was moving the Raspberry Pi out of my office and into the basement. There it continues to collect data, and powers my bitcoin miner (which also doubles as a space heater).

In terms of other things I wish to automate going forward… I really want to get to the point where I have my home’s Christmas lights do cool things. That said, I don’t have $1000’s of dollars to spend just yet, so I’m going to take it year by year I guess to make it happen. This year, I focused on getting the trim decked out with some new LED lighting.

The biggest issue I’ve run into though is electricity… For some strange reason, there are no outlets on the outside of our house. At least, non that are useful. Next summer, I’ll need to look into changing that. I’ll try to do it with the goal in mind of being able to run lots of cable (not just electrical) to my future winter scenes.

I’m also kind of wondering what my neighbor’s do for Christmas. This being the first year in our home, and the first year I’ve been able to decorate, I’m kind of concerned that I may eventually do “to much” (is there such a thing)?

In other news: Link continues to get older. Ellie seems to as well, but I swear not as fast as it went with Link. I feel like Link could be starting 1st grade any day now (okay, maybe not). Being a father is a new challenge every day. But it’s one I am very much enjoying.


Home Automation Part 7 – Systems and Circuits

The last few days of work on the house have been moving more into the practical and less into the measuring stages of things.  And both of these tasks have been involving the word “circuits”.

The first task that I’ve been working away at is trying to get my servo rig up and running. I did manage to get a TI MSP-430 chip to control one of my Futuba S3003 servos (which was pretty cool), but I have yet to get that onto my 1 wire network of devices, which basically means I don’t have a good way to control it. I’ll need to do some circuit work to figure out what 1-wire chip I plan on adding that the MSP-430 can get it’s needed state from. I also need to figure out exactly how I plan no attaching this servo to the damper, and mount it to the wall. And lastly, how I plan on powering it, as parasitic power is not going to be an option for this.

Perhaps it might be time to consider some other options for actually controlling the servo’s other than a bunch of MSP-430 chips with 1 wire supplements… Ardunio anyone? It might still be possible to do 1-wire with the MSP-430 alone… but that is proving difficult.

The other circuit that I’ve been messing with is not electrical, and has proven to be much more difficult to manage. That is the circuit of air flowing throw my house.

My first attempt at getting more cool air upstairs has met rather unexpected results… I added a booster fan (150 to 250 CFM) flowing into the room at the “end of the line” (“Girls Room”).  Instead of cooling the room more (which is what I wanted)… Either nothing happened OR it synced temperatures with another room nearby (Link’s Room). I’m leaning towards the syncing given what I think may have happened in terms of air pressures, especially since it’s quite likely that these 2 rooms share both a supply duct and a return duct.

And while the A/C is capable of overcoming this for both rooms, it does seem to provide some sort of balancing between the two rooms.


The Solid vertical red line is when the fan was kicked on. The 2 lines I’m most interested in on this chart are the green line (The room that has a booster on it now, girls room), and the orange line (Link’s room). While these 2 rooms moved in sync somewhat before with divergence occuring in the morning and evening… it appears that they now *greatly* moved together… so much so that the lines almost trace each other… Despite what the sun might be doing.

I should add for the sake of this that the blower fan is also running constantly pretty much throughout this entire chart. I’ll be curious what the booster does once I shut the blower off. We shall see.

In any case, I’m learning a lot. Last night’s lessons involved primarily how to cut into duct work and how to install a duct fan… 2 things I had never done before last night. And while it’s not perfect, I feel it was a great first attempt at balancing out the system… Now if only I could put some more effort into the servo side of things, I might eventually get my graph to be perfect… we shall see.