Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove aspect ratio check from upload_image.py #5806

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions scripts/upload_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
1200,
]

ASPECT_RATIO_RANGE = (1.6, 1.8)


def build_image_stack(image: Image) -> list[tuple[int | None, Image]]:
image_stack: list[tuple[int | None, Image]] = [(None, image)]
Expand Down Expand Up @@ -120,32 +118,14 @@ def image_from_clipboard() -> Image:


class Uploader:
def __init__(self, auto_accept: bool):
def __init__(self):
gcs = storage.Client("rerun-open")
self.bucket = gcs.bucket("rerun-static-img")
self.auto_accept = auto_accept

def _check_aspect_ratio(self, image: Path | Image) -> None:
if isinstance(image, Path):
image = PIL.Image.open(image)

aspect_ratio = image.width / image.height
aspect_ok = ASPECT_RATIO_RANGE[0] < aspect_ratio < ASPECT_RATIO_RANGE[1]

if not aspect_ok and not self.auto_accept:
logging.warning(
f"Aspect ratio is {aspect_ratio:.2f} but should be between {ASPECT_RATIO_RANGE[0]} and "
f"{ASPECT_RATIO_RANGE[1]}."
)
# do not pass prompt to input as this goes to stdout
print(
"The image aspect ratio is outside the range recommended for example screenshots. Continue? [y/N] ",
end="",
file=sys.stderr,
)
if input().lower() != "y":
sys.exit(1)

def upload_file(self, path: Path) -> str:
"""
Upload a single file to Google Cloud.
Expand Down Expand Up @@ -355,7 +335,7 @@ def download_file(url: str, path: Path) -> None:
def run(args: argparse.Namespace) -> None:
"""Run the script based on the provided args."""
try:
uploader = Uploader(args.auto_accept)
uploader = Uploader()

if args.single:
if args.path is None:
Expand Down Expand Up @@ -415,7 +395,6 @@ def main() -> None:
"--single", action="store_true", help="Upload a single image instead of creating a multi-resolution stack."
)
parser.add_argument("--name", type=str, help="Image name (required when uploading from clipboard).")
parser.add_argument("--auto-accept", action="store_true", help="Auto-accept the aspect ratio confirmation prompt")
parser.add_argument("--debug", action="store_true", help="Enable debug logging.")
args = parser.parse_args()

Expand Down
Loading