Skip to content

Instantly share code, notes, and snippets.

@oriolrivera
Created December 1, 2014 00:38
Show Gist options
  • Save oriolrivera/1743534fa7e9087524e7 to your computer and use it in GitHub Desktop.
Save oriolrivera/1743534fa7e9087524e7 to your computer and use it in GitHub Desktop.
Cortar una Imagen con PHP
<?php
$filename= "ejemplo-de-imagen.jpg";
list($w, $h, $type, $attr) = getimagesize($filename);
$src_im = imagecreatefromjpeg($filename);
$src_x = '0'; // comienza x
$src_y = '0'; // comienza y
$src_w = '100'; // ancho
$src_h = '100'; // alto
$dst_x = '0'; // termina x
$dst_y = '0'; // termina y
$dst_im = imagecreatetruecolor($src_w, $src_h);
$white = imagecolorallocate($dst_im, 255, 255, 255);
imagefill($dst_im, 0, 0, $white);
imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
header("Content-type: image/png");
imagepng($dst_im);
imagedestroy($dst_im);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment