The Deployer

October 26, 2007

PHP JPEG image resizing

Filed under: PHP — Lucian Daniliuc @ 06:22

Destul de des, atunci cand dezvoltam orice fel de site in care clientul trebuie sa poata pune pe site niste imagini, mai mult ca sigur ca acele imagini sunt de cativa megapixeli si afisarea lor la dimensiunile dorite este de multe ori un task destul de dificil de realizat. Asa am gasit pe netlobo.com un articol dragut cu o functie simpla si scurta care face resize la orice jpeg in anumite dimensiuni maximale, fara sa distorsioneze imaginea:


function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile )
{

$fw = $forcedwidth;
$fh = $forcedheight;
$is = getimagesize( $sourcefile );
if(
$is[0] >= $is[1] )
{
$orientation = 0;
}
else
{
$orientation = 1;
$fw = $forcedheight;
$fh = $forcedwidth;
}
if (
$is[0] > $fw || $is[1] > $fh )
{
if( (
$is[0] - $fw ) >= ( $is[1] - $fh ) )
{
$iw = $fw;
$ih = ( $fw / $is[0] ) * $is[1];
}
else
{
$ih = $fh;
$iw = ( $ih / $is[1] ) * $is[0];
}
$t = 1;
}
else
{
$iw = $is[0];
$ih = $is[1];
$t = 2;
}
if (
$t == 1 )
{
$img_src = imagecreatefromjpeg( $sourcefile );
$img_dst = imagecreatetruecolor( $iw, $ih );
imagecopyresampled( $img_dst, $img_src, 0, 0, 0, 0, $iw, $ih, $is[0], $is[1] );
if( !
imagejpeg( $img_dst, $destfile, 90 ) )
{
exit( );
}
}
else if (
$t == 2 )
{
copy( $sourcefile, $destfile );
}
}

?>

Daca acest copy-paste nu arata chiar ok, vezi articolul original.

October 17, 2007

PHP5 Singleton pattern

Filed under: PHP — Lucian Daniliuc @ 07:15
class Singleton {    static private $instance = NULL;

    private function __construct() {    }

    static public function getInstance() {        if (self::$instance == NULL) {            self::$instance = new Singleton();        }        return self::$instance;    }}

(source: http://devzone.zend.com/node/view/id/1714)

October 4, 2007

PHP: Zend Framework

Filed under: PHP — Lucian Daniliuc @ 08:57

PROLOG: Am suflat un pic praful care s-a asezat pe acest blog, asa ca mai bag o fisa si continui:

Zend framework pare un framework perfect pentru orice fel de aplicatie ai avea neovie sa dezvolti. Am studiat un pic si Symfony, si noua versiune de CodeIgniter care a ajuns la versiunea 1.5.4.
Symfony mi s-a parut super-dragutz dar putin prea “automatizat” pentru gusturile mele.

March 2, 2005

JpGraph – Outstanding graphs

Filed under: PHP — Lucian Daniliuc @ 07:58

If you wanna include free graphs in your website, check out these features… JpGraph – Image Gallery

« Newer Posts

Powered by WordPress