Monthly Archives: July 2012

How to delete blank lines from code in Netbeans

Formatting in Netbeans will not delete all the blank lines and sometimes we want this. For example, when the charset is messed up and the blank spaces are doubled because CR and LF – Unix – Windows compatibility.

Solution: Ctrl-F (find) in Netbeans as Regular Expression:

\n\s*(\n)

and Replace All by

$1

A special thanks to http://seo.911web.org/netbeans-how-to-delete-blank-lines

Image resize in php

Here there are some basic help for image resizing code in php


function get_width($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_width;
}

function get_height($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_height;
}

function get_ratio($mages) {
    list($img_width, $img_height) = getimagesize($mages);
    return $img_width / $img_height;
}

function get_type($mages) {
    list($img_width, $img_height, $type, $attr) = getimagesize($mages);
    return $type;
}

function get_mime($mages) {
    $array = getimagesize($mages);
    return $array['mime'];
}

function resize($width, $height, $img) {

    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $image_aspect_ratio = $image_width / $image_height;
    $image_type = get_type($img);
    $image_mime = get_mime($img);

    $new_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
    if(file_exists('resized-imges/sample2.jpg'))
        unlink('resized-imges/sample2.jpg');
    imagejpeg($new_image, 'resized-imges/sample2.jpg', 100);

    imagedestroy($new_image);
}

function resizeToHeight($height, $img) {

    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $ratio = $height / $image_height;
    $width = $image_width * $ratio;
    resize($width, $height, $img);
}

function resizeToWidth($width, $img) {
    $old_image = imagecreatefromjpeg($img);
    $image_width = imagesx($old_image);
    $image_height = imagesy($old_image);
    $ratio = $width / $image_width;
    $height = $image_height * $ratio;
    resize($width, $height, $img);
}

$img = ('images/Shrek2-3.jpg');

resizeToWidth(600, $img);

%d bloggers like this: