function check_size_and_rotation($pathname) { require_once mnminclude . "simpleimage.php"; $original = $pathname; $tmp = "{$pathname}.tmp"; $max_size = 2048; $image = new SimpleImage(); if ($image->rotate_exif($pathname)) { if ($image->save($tmp)) { $pathname = $tmp; clearstatcache(); } } if (filesize($pathname) > 1024 * 1024) { // Bigger than 1 MB if ($image->load($pathname) && ($image->getWidth() > $max_size || $image->getHeight() > $max_size)) { if ($image->getWidth() > $image->getHeight) { $image->resizeToWidth($max_size); } else { $image->resizeToHeight($max_size); } if ($image->save($tmp)) { $pathname = $tmp; clearstatcache(); } } } if ($pathname != $original && file_exists($pathname)) { if (!@rename($pathname, $original)) { syslog(LOG_INFO, "Error renaming file {$pathname} -> {$original}"); @unlink($pathname); } } $this->size = filesize($original); @chmod($original, 0777); return true; }
} } } $tmpfile = $dir . '/' . $current_user->user_id . '-' . $current_user->user_login . '-' . uniqid(); if (file_put_contents($tmpfile, $source)) { $info = getimagesize($tmpfile); if (!$info) { @unlink($tmpfile); $r->error = _('imagen no soportada'); echo json_encode($r); die; } $ext = image_type_to_extension($info[2]); $uploadfile = $tmpfile . $ext; @rename($tmpfile, $uploadfile); require_once mnminclude . "simpleimage.php"; $image = new SimpleImage(); if ($image->rotate_exif($uploadfile)) { $image->save($uploadfile); } $r->type = $info['mime']; $r->name = basename($uploadfile); $r->url = $globals['base_static'] . Upload::get_cache_relative_dir() . '/tmp/' . $r->name; $r->thumb = $globals['base_static'] . Upload::get_cache_relative_dir() . "/tmp/tmp_thumb-{$r->name}"; // Creates the thumbnail $thumb = new SimpleImage(); $thumb->load($uploadfile); $thumb->resize($globals['media_thumb_size'], $globals['media_thumb_size'], true); $thumb->save(dirname($uploadfile) . "/tmp_thumb-{$r->name}", -1); echo json_encode($r); }