Skip to content

Instantly share code, notes, and snippets.

@locvfx
Created December 19, 2018 13:37
Show Gist options
  • Save locvfx/04539cfd3c5b4ed44c2de851f9c95f49 to your computer and use it in GitHub Desktop.
Save locvfx/04539cfd3c5b4ed44c2de851f9c95f49 to your computer and use it in GitHub Desktop.
Crop and resize image
<?php
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment