Daily Archives: August 27, 2012


Incorrect integer value – How to change mysql sql_mode

You might be an unlucky soul me where you need to maintain a bunch of old and poorly written code. You’ll also probably get a bunch of weird errors if you’re running recent versions of PHP and mysql locally such as “invalid integer value xxx” when trying to modify a record. This occurs because the application is probably trying to insert a string into an INT field in mysql. Anyway, since the number of bugs are too numerous to fix in this application, the easiest solution is to remove the strict settings from your mysql.

To view the current sql mode setting:

SELECT @@sql_mode;

To remove all settings (and allow string to get inserted into INT cols)

SET global sql_mode="";

How to center a thumbnail image using CSS

Use this trick to create a good looking thumbnail gallery where all the images are displayed at the same size without distortion. The sample code below is from this useful tutorial http://selbie.wordpress.com/2011/01/23/scale-crop-and-center-an-image-with-correct-aspect-ratio-in-html-and-javascript/ . Determine the image height and width to calculate the offset so the image will be centered.

<div style="width: 150px; height: 150px; border: thick solid #666666; overflow: hidden; position: relative;">
    <img src="tanahlot.jpg" style="position: absolute; left:-37px; width:225px; height: 150px;"/>
</div>

PHP get image size of remote image

Below is how to determine the height and width of a remote image using PHP

$thumbnail = imagecreatefromstring(file_get_contents("https://www.google.com/images/srpr/logo3w.png"));
$thumbnailWidth = imagesx($thumbnail);
$thumbnailHeight = imagesy($thumbnail);