Facebook

Sunday, January 31, 2016


Web config file - alternative of htaccess in windows machine
<?xml version="1.0" encoding="UTF-8"?> <configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Clean URL" stopProcessing="true">

                <match url="^news/(.*).html" />
                <action type="Rewrite" url="/newssingle.php?url={R:1}" appendQueryString="true" />

                </rule>
                <rule name="Clean URL 1" stopProcessing="true">

                <match url="^index.html" />
                <action type="Rewrite" url="index.php" appendQueryString="true" />

                </rule>
                <rule name="Clean URL 2" stopProcessing="true">

                <match url="^newsevents.html" />
                <action type="Rewrite" url="newsevents.php" appendQueryString="true" />

                </rule>
                <rule name="Clean URL 3" stopProcessing="true">

                <match url="^contactus.html" />
                <action type="Rewrite" url="contactus.php" appendQueryString="true" />

                </rule>
                <rule name="Clean URL 4" stopProcessing="true">

                <match url="^services.html" />
                <action type="Rewrite" url="services.php" appendQueryString="true" />

                </rule>
                <rule name="Clean URL 5" stopProcessing="true">

                <match url="^aboutus.html" />
                <action type="Rewrite" url="aboutus.php" appendQueryString="true" />

                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Clean URL" stopProcessing="true">
                    <match url="^(.*).html" />
                    <action type="Rewrite" url="/pages.php?page_slug={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Wednesday, January 6, 2016

Responsive design: Tips and tricks


1. Usage: Make colorbox responsive.

$(document).ready(function() {
    $(".ajax-popup").colorbox({width: "90%",maxWidth: "900px", maxHeight:'90%'});
})

1. Usage: JQuery ui date picker limit date range.

$(document).ready(function() {
    $( "#datePicker" ).datepicker({
        maxDate: "+1M +10D -15Y",
        minDate: -20
    })
})

Saturday, January 2, 2016

Function to render text as image - escape spam bots


Escaping contact information from spam bots is one of the major challenges developers facing. Converting the text to image and rendering as image is one basic solution. Here is a function I use.
Function to render text as image
<img src="<?php echo render_text_image('test image', 183, 50);?>" />


function render_text_image($string, $width, $height, $text_align_pos = 0)
{


    $img = imagecreatetruecolor($width, $height);

    $imageX = imagesx($img);
    $imageY = imagesy($img);

    imagealphablending($img, false);
    imagesavealpha($img, true);

    $transparent = imagecolorallocatealpha($img, 255,255,255, 127);
    $white = imagecolorallocate($img, 129, 78, 16);
    $black = imagecolorallocate($img, 0, 0, 0);
    $grey = imagecolorallocate($img, 127,127,127);
    //imagefilledrectangle($img, 0, 0, $imageX, $imageY, $grey);
    imagefilledrectangle($img, 0, 0, $imageX, $imageY, $transparent);

    $font = ROOT_DIRECTORY . "assets/font/arialbd.ttf";
    //$font = ROOT_DIRECTORY . "assets/font/arialbd.ttf";
    $fontSize = 12;
    $text = $string;

    $textDim = imagettfbbox($fontSize, 0, $font, $text);
    $textX = $textDim[2] - $textDim[0];
    $textY = $textDim[7] - $textDim[1];

    $text_posX = ($text_align_pos== "center") ? ($imageX / 2) - ($textX / 2) : $text_align_pos;
    $text_posY = ($imageY / 2) - ($textY / 2);

    imagealphablending($img, true);
    imagettftext($img, $fontSize, 0, $text_posX, $text_posY, $white, $font, $text);
    //ImageString($img,2,0,0, $text,$black);
    //Get image to a variable
    ob_start();
    imagepng($img);
    // Capture the output
    $imagedata = ob_get_contents();
    // Clear the output buffer
    ob_end_clean();

    return "data:image/png;base64," . base64_encode($imagedata);
}