First in your first loop why do you break it? if there is no image in image_5
if someone just skip this and continue to image_6
?
Second the ACF image field can return you an array with all the sizes. you need to set the field to return you Image Array
And then you can do something like this.
for($x = 1; $x <= 10; $x++) {
$img = get_field('image_' . $x);
if($img) {
?>
<a href="https://wordpress.stackexchange.com/questions/286121/<?php echo $img["url']; ?>" class="open-viewer">
<img src="https://wordpress.stackexchange.com/questions/286121/<?php echo $img["sizes']['scaled']; ?>" alt="https://wordpress.stackexchange.com/questions/286121/<?php echo $img["alt']; ?>">
</a>
<?php
}
}
In case you can’t return Image Array and you return the Image ID
for($x = 1; $x <= 10; $x++) {
$img_id = get_field('image_' . $x);
if($img_id) {
$fullsize_image = wp_get_attachment_image_src($img_id, 'full');
?>
<a href="https://wordpress.stackexchange.com/questions/286121/<?php echo $fullsize_image[0]; ?>" class="open-viewer">
<?php echo wp_get_attachment_image($img_id, 'scaled'); ?>
</a>
<?php
}
}