git-svn-id: https://msi/svn/firstRepo/Service/branches/Slim3@39 0f545695-f87b-41b6-9a03-7f16563b5454
This commit is contained in:
+115
@@ -0,0 +1,115 @@
|
||||
<?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($response, $callbackFn, $retObj) {
|
||||
$contentType = "";
|
||||
$body = "";
|
||||
if ($callbackFn) {
|
||||
$contentType = 'application/javascript; Charset=UTF-8';
|
||||
$body = $callbackFn . "(" . html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1') . ")";
|
||||
} else {
|
||||
$contentType = 'application/x-json; Charset=UTF-8';
|
||||
$body = html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
}
|
||||
|
||||
return $response->withHeader(
|
||||
'Content-Type',
|
||||
'application/json'
|
||||
)->write($body);
|
||||
}
|
||||
|
||||
function returnJson($response, $callbackFn, $retObj) {
|
||||
$contentType = "";
|
||||
$body = "";
|
||||
if ($callbackFn) {
|
||||
$contentType = 'application/javascript; Charset=UTF-8';
|
||||
$body = $callbackFn . "(" . (json_encode(utf8json($retObj))) . ")";
|
||||
} else {
|
||||
$contentType = 'application/x-json; Charset=UTF-8';
|
||||
$body = (json_encode(utf8json($retObj)));
|
||||
}
|
||||
|
||||
return $response->withHeader(
|
||||
'Content-Type',
|
||||
'application/json'
|
||||
)->write($body);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user