Create a responsive WordPress attachment page

Create a new file in your theme folder called “single-attachment.php”.

Replace

with:

<?php 
$image_info = getimagesize($post->guid); var_dump($image_info); 
$imgclass = "";
if ($image_info[0] >  1280) // replace 1280 with your max width
{
	$imgclass = "resposiveattachment";
}
?>
<img class="<?php echo $imgclass; ?>" src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" <?php echo $image_info[3]; ?> />

Add the following CSS to your site:

.resposiveattachment { width:100%!important; height:auto!important;}