Skip to content

Instantly share code, notes, and snippets.

@noodlehaus
Last active September 26, 2015 07:58
Show Gist options
  • Save noodlehaus/66dbc0a1887706d523a9 to your computer and use it in GitHub Desktop.
Save noodlehaus/66dbc0a1887706d523a9 to your computer and use it in GitHub Desktop.
resample uploaded images (old version)
<?php
function save_and_resample($fname, $oname, $tname, $type, $imagew, $imageh)
{
$imgr = ( $imagew > $imageh ) ? IMAGE_MAX_THUMB_WIDTH/$imagew : IMAGE_MAX_THUMB_HEIGHT/$imageh ;
$neww = $imagew * $imgr;
$newh = $imageh * $imgr;
$fulw = $imagew;
$fulh = $imageh;
if ( $neww > IMAGE_MAX_THUMB_WIDTH ) {
$newh = $newh * IMAGE_MAX_THUMB_WIDTH/$neww;
$neww = IMAGE_MAX_THUMB_WIDTH;
} else if ( $newh > IMAGE_MAX_THUMB_HEIGHT ) {
$neww = $neww * IMAGE_MAX_THUMB_HEIGHT/$newh;
$newh = IMAGE_MAX_THUMB_HEIGHT;
}
if ( $fulw > IMAGE_MAX_WIDTH || $fulh > IMAGE_MAX_HEIGHT ) {
$fulw = $neww * 10;
$fulh = $newh * 10;
}
$thmb = imagecreatetruecolor( $neww, $newh );
$full = imagecreatetruecolor( $fulw, $fulh );
$orig = ( $type == IMAGETYPE_JPEG ) ? imagecreatefromjpeg( $fname ) : imagecreatefrompng( $fname ) ;
imagecopyresampled( $thmb, $orig, 0, 0, 0, 0, $neww, $newh, $imagew, $imageh );
imagecopyresampled( $full, $orig, 0, 0, 0, 0, $fulw, $fulh, $imagew, $imageh );
// create thumb and copy of original
imagejpeg( $thmb, $tname, 100 );
imagejpeg( $full, $oname, 100 );
}
function get_uploaded_image_info($fname)
{
$info = null;
if ( is_uploaded_file( $fname ) ) {
$info = getimagesize( $fname );
}
return $info;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment