function wppa_make_o1_source($id)
{
    // Init
    $src_path = wppa_get_source_path($id);
    // Source available?
    if (!is_file($src_path)) {
        return false;
    }
    // Only needed for non-standard orientations
    $orient = wppa_get_exif_orientation($src_path);
    if (!in_array($orient, array('2', '3', '4', '5', '6', '7', '8'))) {
        return false;
    }
    // Only on jpg file type
    $ext = wppa_get_ext($src_path);
    if (!in_array($ext, array('jpg', 'JPG', 'jpeg', 'JPEG'))) {
        return false;
    }
    // Make destination path
    $dst_path = wppa_get_o1_source_path($id);
    // Copy source to destination
    copy($src_path, $dst_path);
    // Correct orientation
    if (!wppa_orientate_image_file($dst_path, $orient)) {
        unlink($dst_path);
        return false;
    }
    // Done
    return true;
}
function wppa_upload_to_cloudinary($id)
{
    $prefix = is_multisite() && !WPPA_MULTISITE_GLOBAL ? $blog_id . '-' : '';
    $args = array("public_id" => $prefix . $id, "version" => get_option('wppa_photo_version', '1'), "invalidate" => true);
    // Try proper oriented source
    $file = wppa_get_o1_source_path($id);
    if (!is_file($file)) {
        // Try source
        $file = wppa_get_source_path($id);
    }
    if (!is_file($file)) {
        // Use display file
        $file = wppa_get_photo_path($id);
    }
    // Doit
    if (is_file($file)) {
        \Cloudinary\Uploader::upload($file, $args);
    }
}
function wppa_get_hires_url($id)
{
    // video? return the poster url
    if (wppa_is_video($id) || wppa_has_audio($id)) {
        $url = wppa_get_photo_url($id);
        $url = wppa_fix_poster_ext($url, $id);
        $temp = explode('?', $url);
        $url = $temp['0'];
        return $url;
    }
    // Try CDN
    if (wppa_cdn('front') && !wppa_too_old_for_cloud($id)) {
        switch (wppa_cdn('front')) {
            case 'cloudinary':
                $url = wppa_get_cloudinary_url($id);
                break;
            default:
                $url = '';
        }
        if ($url) {
            return $url;
        }
    }
    // Try the orientation corrected source url
    $source_path = wppa_get_o1_source_path($id);
    if (is_file($source_path)) {
        // The source file is only http reacheable when it is down from wp-content
        if (strpos($source_path, WPPA_CONTENT_PATH) !== false) {
            return str_replace(WPPA_CONTENT_PATH, WPPA_CONTENT_URL, $source_path);
        }
    }
    // Try the source url
    $source_path = wppa_get_source_path($id);
    if (is_file($source_path)) {
        // The source file is only http reacheable when it is down from ABSPATH
        if (strpos($source_path, WPPA_CONTENT_PATH) !== false) {
            return str_replace(WPPA_CONTENT_PATH, WPPA_CONTENT_URL, $source_path);
        }
    }
    // The medium res url
    $hires_url = wppa_get_photo_url($id);
    $temp = explode('?', $hires_url);
    return $temp['0'];
}