• Krāsu kods no STRING

    No STRING ģenerē HTML krāsas kodu

    function stringToColorCode($str) {
    $code = dechex(crc32($str));
    $code = substr($code, 0, 6);
    return $code;
    }


  • PHP kvadrātainu thumbnail griezšana

    PHP kvadrātainu thumbnail griezšana

    function LoadJpeg($imgname)
    {

    $im = @imagecreatefromjpeg($imgname);

    if(!$im)
    {

    $im = imagecreatetruecolor(150, 30);
    $bgc = imagecolorallocate($im, 255, 255, 255);
    $tc = imagecolorallocate($im, 0, 0, 0);

    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

    imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    $thumb_size = 100;
    $size = getimagesize($imgname);
    $width = $size[0];
    $height = $size[1];

    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } elseif($height> $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
    $new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);

    return $new_im;
    }


  • Attēla kvadrāta thumbnail izgriezšana PHP

    function LoadJpeg($imgname,$izmers)
    {
    $im = @imagecreatefromjpeg($imgname);
    if(!$im)
    {
    $im = imagecreatetruecolor(150, 30);
    $bgc = imagecolorallocate($im, 255, 255, 255);
    $tc = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
    imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
    $size = getimagesize($imgname);
    $width = $size[0];
    $height = $size[1];
    if($width> $height) {
    $x = ceil(($width - $height) / 2 );
    $width = $height;
    } else{
    $y = ceil(($height - $width) / 2);
    $height = $width;
    }
    $thumb_size1=$izmers;
    $thumb_size2=$izmers;

    $new_im = ImageCreatetruecolor(($thumb_size1),$thumb_size2);
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size1,$thumb_size2,$width,$height);

    return $new_im;
    }


  • Login with Facebook – tas patiesībā ir graujoši vienkārši

    Pirmā koda daļa nodrošina pliku pieslēgšanos.
    Atliek vien noreģistrēt savu websaitu “facebook apps” un iegūt APP_ID, APP_SECRET utt.
    <fb:login-button autologoutlink="true" style="display:table-cell;padding:3px;" ></fb:login-button>
    <p><fb:like></fb:like></p>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
    FB.init({appId: '235xxxxxxxxxxxxxxx', status: true, cookie: true,
    xfbml: true});
    };
    (function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
    '//connect.facebook.net/lv_LV/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    }());
    </script>

    Lai tiktu pie lietotāja Facebook datiem… spēlējamies tālāk…

    <?php
    define('YOUR_APP_ID', '235xxxxxxxxxxxxxxx');
    define('YOUR_APP_SECRET', 'c9fb5xxxxxxxxxxxxxxxxxxxxxxxxx');

    function get_facebook_cookie($app_id, $app_secret) {
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
    if ($key != 'sig') {
    $payload .= $key . '=' . $value;
    }
    }
    if (md5($payload . $app_secret) != $args['sig']) {
    return null;
    }
    return $args;
    }

    $cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);

    $user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']));

    ?>
    <?php if ($cookie) { ?>
    Welcome <?= $user->name ?>
    <?php print_r($user); ?>
    <?php } else { ?>
    <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
    cookie: true, xfbml: true});
    FB.Event.subscribe('auth.login', function(response) {
    window.location.reload();
    });
    </script>


  • md5 hash ģenerators

    http://md5.jaaniic.lv


  • php IF īsā forma

    $x = ($myvalue == 10) ? "the value is 10": "the value is not 10";