Files
IlLievitario-Service/utility.php
T

123 lines
3.5 KiB
PHP

<?php
if ( ! function_exists( 'exif_imagetype' ) ) {
function exif_imagetype ( $filename ) {
if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {
return $type;
}
return false;
}
}
function utf8json($inArray) {
if (is_array($inArray)) {
static $depth = 0;
/* our return object */
$newArray = array();
/* safety recursion limit */
$depth ++;
if ($depth >= '300000') {
return false;
}
/* step through inArray */
foreach ($inArray as $key => $val) {
if (is_array($val)) {
/* recurse on array elements */
$newArray[$key] = utf8json($val);
} else {
/* encode string values */
$newArray[$key] = utf8_encode($val);
}
}
/* return utf8 encoded array */
return $newArray;
}
/* return utf8 encoded array */
return $inArray;
}
function returnJsonWithDecode($app, $callbackFn, $retObj) {
if ($callbackFn) {
$app->contentType('application/javascript; Charset=UTF-8');
echo $callbackFn . "(" . html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1') . ")";
} else {
$app->contentType('application/x-json; Charset=UTF-8');
echo html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
}
}
function returnJson($app, $callbackFn, $retObj) {
if ($callbackFn) {
$app->contentType('application/javascript; Charset=UTF-8');
echo $callbackFn . "(" . (json_encode(utf8json($retObj))) . ")";
} else {
$app->contentType('application/x-json; Charset=UTF-8');
echo (json_encode(utf8json($retObj)));
}
}
function makeThumbnail($im) {
$final_width_of_image = 300;
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
return $nm;
}
function getContentFromResources($res) {
ob_start(); //Start output buffer.
imagejpeg($res); //This will normally output the image, but because of ob_start(), it won't.
$contents = ob_get_contents(); //Instead, output above is saved to $contents
ob_end_clean(); //End the output buffer.
return $contents;
}
function resizeImage($dropBoxObj, $layer, $size, $dir, $fileName, $dirDropBox)
{
$fullPath = $dir . "/" . $fileName;
$layer->resizeByLargestSideInPixel($size, true);
$layer->save($dir, $fileName);
try {
$dropBoxObj->CreateFolder($dirDropBox);
} catch (DropboxException $ex) {
}
$dropBoxObj->UploadFile($fullPath, $dirDropBox . "/" . $fileName);
return $dropBoxObj->GetLink($dirDropBox . "/" . $fileName);
}
function makeThumbImage($dropBoxObj, $layer, $size, $dir, $fileName, $dirDropBox)
{
$fileName = str_replace(".jpg", ".png", $fileName);
$fileName = str_replace(".jpeg", ".png", $fileName);
$fullPath = $dir . "/" . $fileName;
$layer->resizeInPixel($size, $size, true, 0, 0, 'MM');
$layer->save($dir, $fileName);
try {
$dropBoxObj->CreateFolder($dirDropBox);
} catch (DropboxException $ex) {
}
$dropBoxObj->UploadFile($fullPath, $dirDropBox . "/" . $fileName);
return $dropBoxObj->GetLink($dirDropBox . "/" . $fileName);
}
?>