Solved

Maximum Image Size On Front Page

Posted on 2010-11-10
7
470 Views
Last Modified: 2012-05-10
http://www.tornadoeskick.com

I am wondering if a code exists to resize images on the front page so that they fit within the column widths. I do not use the media uploader in WP. Instead, I upload my images to image folders within my site and link using the standard IMG command.

The front page displays the entry in a two column layout that is smaller than my standard image size (700px). However, single article pages do not have the sidebar and thus expand the content area to accommodate the images.

Is there a code I can add to the front page file that will resize any images bigger than 500px to a set size (i.e. 500px)?

Thanks all!
0
Comment
Question by:laubacht
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
ID: 34107974
I am not positive I completely understand all of your requirements. I will start off by providing a link to an article which I believe addresses what you are asking for. Let me know if I am wrong, and I will look again.

LINK: http://soulsizzle.com/wordpress/adding-additional-image-sizes-to-wordpress-themes/
0
 
LVL 15

Accepted Solution

by:
AndyBeard earned 334 total points
ID: 34108903
The easy way is to just use CSS and rely on a browser to do a sufficient job of rendering the image.

The programming solution would be to use something like http://code.google.com/p/timthumb/

You could then write some javascript/jquery that would modify each image URL and pass it to timthumb

Alternatively if you uploaded smaller versions each time, you could just use some javascript to modify image src.
0
 
LVL 1

Author Comment

by:laubacht
ID: 34109376
Thanks guys, I am going to give both options a look and test them out..

Jeremy, basically what I am going for is a resize on the front page to fit the column width.  Since I run my images through a program that resizes, renames, and watermarks all my images, I upload them via standard FTP to a directory in my site to which I store them and call them via IMG SRC commands to post into pages.  With that said, I do not use the media tools supplied by Wordpress.  The issue is my standard resize is 700px wide; my front page column for an article is only 500 pixels wide.

If you go to my website (http://www.tornadoeskick.com), you'll notice that the images in the first entry spill out on the right cause they are too big.  However, if you open up the single article page which has no sidebar (and thus is only one column), it'll fit fine.

What I want to do is make it so any articles displayed on the front page automatically resize my image to a specified size (or percentage) so it'll fit on the front page.  But if a user opens the single article, it will display as normal.

Its hard to make sense of this, but that's something I hope makes sense.

Below is a code sample I found today...

So something like that perhaps?

To better give a visual, go to my front page at http://www.tornadoeskick.com/ and scroll down to the first article titled "First Snow Of 10/11 Season".  Notice how the image of the three cars with the snow falling is too big for the column (its 700px by default) and thus spills out on the right side.  If you display the article on its own (via http://www.tornadoeskick.com/2010/11/4236), it fits fine given the lack of the sidebar.

What I want to do is make it so images being displayed on the front page automatically get displayed with a smaller width so they fit, but then display like normal when on its own.

Does that help a bit?

Thanks again guys!
.rt-article-content img {
       max-width:100%;
       height:100%;
}

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Assisted Solution

by:Sam Cohen
Sam Cohen earned 166 total points
ID: 34109501
If the wordpress theme is already coded to show the image..look for that code and just add width="500" or style="width:500px;" to the image tag of the loop...do not add a height attribute
0
 
LVL 8

Expert Comment

by:Sam Cohen
ID: 34109507
or if you want to use instead ...
just add height="500" or style="height:500px;" to the image tag of the loop...but DO NOT add a width attribute
0
 
LVL 15

Assisted Solution

by:AndyBeard
AndyBeard earned 334 total points
ID: 34109627
The css route is really easy... though much easier if just one of those nested DIVs, or just a unique class was applied to all your historical photos.

then you could just add this to your CSS

.home .imghome {max-width:500px;}

You could use that aligncenter if it isn't used for anything else anywhere.

That being said it will squish things.

Probably the best solution possible is to create a shortcode

We can grab a shortcode from this post
http://www.jauhari.net/resize-images-using-shortcode-with-timthumb.jsp

// Image resize in content
function timmyimg($atts, $content = null) {
      extract(shortcode_atts(array(
            'w' => '540',
            'h' => '250',
            'class' => 'alignnone',
            'alt' => ''
      ), $atts));
      return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";
}
add_shortcode('img', 'timmyimg');


Then modify it with a is_singular conditional to return an unmodified width.

thus something like

if is_singular {

return "<img src='" . $content . "' alt=".$alt." class='wp-post-img ".$class."' />";

} else

return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";
}


I am sure there are some bugs in that but you will get the idea. (I just tinker with code)
0
 
LVL 1

Author Comment

by:laubacht
ID: 34199659
So the trick was to modify my template.css file to include the lines of code below.. this adjusted the images displayed onthe front to a max size of 600px, maintain the aspect ratio of the original image, but display the image normally on the single post pages.
.rt-article-content img {
	max-width:600px;
	height:100%;
}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
setup local host on network so everyone can access web page? 5 44
WooCommerce Sort by Date 4 34
Wordpress syntax error 1 40
logo getting cutoff on ipad 30 115
Wordpress Horizontal Drop-Down Menu In this tutorial I will show you had to add a WordPress horizontal navigation menu to your theme. I have searched and searched for a good tutorial on creating a WordPress nav menu without adding a plug-in or us…
This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now