Skip to content

Instantly share code, notes, and snippets.

@indapublic
Created November 24, 2014 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indapublic/d1869e98c74369178934 to your computer and use it in GitHub Desktop.
Save indapublic/d1869e98c74369178934 to your computer and use it in GitHub Desktop.
<?
require_once '../../CImage.php';
$sourceFileName = '../../webroot/img/issue40/1280x720.jpg';
$resultFileName = '../../webroot/img/issue40/652x466.jpg';
$imgOptions = array(
'newWidth' => 652,
'newHeight' => 466,
'no-ratio'
);
$img = new CImage();
$img->setSource(basename($sourceFileName), dirname($sourceFileName))
->setOptions($imgOptions)
->loadImageDetails()
->initDimensions()
->calculateNewWidthAndHeight()
->setSaveAsExtension('jpg')
/*
->setJpegQuality(70)
->setPngCompression(NULL)
->useOriginalIfPossible(TRUE)
->useCacheIfPossible(FALSE)
*/
->load()
->preResize()
->resize()
->postResize()
->setPostProcessingOptions(array(
'png_filter' => FALSE,
'png_deflate' => FALSE,
'jpeg_optimize' => FALSE
))
->save(basename($resultFileName), dirname($resultFileName));
if (!file_exists($resultFileName))
die('Result file is not exists :(');
$resultFileSizes = getimagesize($resultFileName);
echo $resultFileSizes[0] . 'x' . $resultFileSizes[1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment