Cut image with PHP

1

Is there any other code in PHP to crop an image from MySQL ?

I'm using this, but it's giving a problem with slider of wow slider

Follow the code:

<?php
//<img src='thumb.php?end=uploads/...&largura=...&altura=...'>

$largura = $HTTP_GET_VARS['largura'];
$altura = $HTTP_GET_VARS['altura'];

$jpeg = $HTTP_GET_VARS['end'];


if($d=getimagesize($jpeg)){
    if (!$largura or $largura==0) $largura = ($altura*$d[0])/$d[1];
    if (!$altura or $altura==0) $altura = ($largura*$d[1])/$d[0];
    $p_final = $largura/$altura;
    $p_orig = $d[0]/$d[1];

    if ($p_orig >= $p_final) {
        $nova_largura = ($d[0]-(($largura*$d[1])/$altura))/2;
        $x_i = $nova_largura;
        $x_f = $d[0]-$nova_largura*2;

        $y_i = 0;
        $y_f = $d[1];
    } else {
        $x_i = 0;
        $x_f = $d[0];

        $nova_altura = ($d[1]-(($altura*$d[0])/$largura))/2;
        $y_i = $nova_altura;
        $y_f = $d[1]-$nova_altura*2;
    }

    header('Content-type: image/jpeg');

    $src = imagecreatefromjpeg($jpeg);
    $dst = ImageCreateTrueColor($largura, $altura);
    $white = imagecolorallocate($dst,255,255,255);  
    imagefill($dst,0,0,$white);

    imagecopyresampled($dst,$src,0,0,$x_i,$y_i,$largura,$altura,$x_f,$y_f);
    imagejpeg($dst, null, 98);
    imagedestroy($dst);
    imagedestroy($src);
}
?>
    
asked by anonymous 02.07.2014 / 14:19

1 answer

1

Use the Timthumb library to do this.

  

Take her here

It is used as follows:

<img src="timthumb.php?src=url_da_imagem&w=100&h=150" alt="">

Where:

w = Width you want for the image

h = Height you want for the image

It accepts several parameters that you can find in documentation . Just follow the examples

    
02.07.2014 / 14:34