You can alter the foreach loop as follows,
foreach( $gallery['ids'] as $attachment_id )
{
$image_attributes = wp_get_attachment_image_src( $attachment_id );
if( $image_attributes ) {
$src = isset($image_attributes[0])? $image_attributes[0] : '';
if(!empty($src)) {
?>
<a href="https://wordpress.stackexchange.com/questions/118897/<?php echo $src; ?>" rel="prettyPhoto[pp_gal]"><img src="https://wordpress.stackexchange.com/questions/118897/<?php echo $src; ?>" alt="Gallery image" /></a>
<?php
}
}
}
You can specify required dimension, as second parameter for , ‘wp_get_attachment_image_src()’ function.