public function __construct() { header('Content-Type: text/javascript;charset="UTF-8"'); header('Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0'); header('Expires: 0'); $util = new IMUtil(); $util->outputSecurityHeaders(); }
/** * @param bool $testmode */ function __construct($testmode = false) { if (!$testmode) { header('Content-Type: text/javascript;charset="UTF-8"'); header('Cache-Control: no-store,no-cache,must-revalidate,post-check=0,pre-check=0'); header('Expires: 0'); header('X-Content-Type-Options: nosniff'); $util = new IMUtil(); $util->outputSecurityHeaders(); } }
private function outputImage($content) { $rotate = false; if (function_exists('exif_imagetype') && function_exists('imagejpeg') && strlen($content) > 0) { $tmpDir = ini_get('upload_tmp_dir'); if ($tmpDir === '') { $tmpDir = sys_get_temp_dir(); } $temp = 'IM_TEMP_' . str_replace(base64_encode(randomString(12)), DIRECTORY_SEPARATOR, '-') . '.jpg'; if (mb_substr($tmpDir, 1) === DIRECTORY_SEPARATOR) { $tempPath = $tmpDir . $temp; } else { $tempPath = $tmpDir . DIRECTORY_SEPARATOR . $temp; } $fp = fopen($tempPath, 'w'); if ($fp !== false) { fwrite($fp, $content); fclose($fp); $imageType = image_type_to_mime_type(exif_imagetype($tempPath)); if ($imageType === 'image/jpeg') { $image = imagecreatefromstring($content); if ($image !== false) { $exif = exif_read_data($tempPath); if ($exif !== false && !empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $content = imagerotate($image, 180, 0); $rotate = true; break; case 6: $content = imagerotate($image, -90, 0); $rotate = true; break; case 8: $content = imagerotate($image, 90, 0); $rotate = true; break; } } } if ($rotate === true) { header('Content-Type: image/jpeg'); ob_start(); imagejpeg($content); $size = ob_get_length(); header('Content-Length: ' . $size); $util = new IMUtil(); $util->outputSecurityHeaders(); ob_end_flush(); } imagedestroy($image); } unlink($tempPath); } } if ($rotate === false) { echo $content; } }