WordPress Post Thumbnail Resizing Issues - php

I have recently developed a website in WordPress, I have a few thumbnail sizes defined by add_image_size();
For example if you look here: http://bit.ly/kSTU0Q
Images in the right hand channel at the very bottom under 'MORE PRODUCT NEWS' we have this defined for
the_post_thumbnail()
add_image_size( 'side-excerpt', 86, 93);
So would be:
the_post_thumbnail( 'side-excerpt',
array('class' => 'alignleft') );
If you look WordPress does not seem to adhere to my sizing specifications and I have used the 'Regenerate Thumbnails' plugin and this seems to make near as no difference.
Hopefully you guys can shed some light on the situation.
Thanks in advanced!

Looks to me like your issue is with your crop style.
add_image_size has a third property that is crop style and defaults to false (soft proportional cropping.
"Box resizing shrinks an image proportionally (that is, without distorting it), until it fits inside the “box” you’ve specified with your width and height parameters."
The reason that your regenerate thumbnails is not working correctly, is because you are using this soft mode, and it seems like the result you are actually looking for is hard crop.
"in this mode, the image is cropped to match the target aspect ratio, and is then shrunk to fit in the specified dimensions exactly."
so you will want to change
add_image_size( 'side-excerpt', 86, 93);
to
add_image_size( 'side-excerpt', 86, 93, true);
For more information see:
http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/
http://codex.wordpress.org/Function_Reference/add_image_size

Related

Full image instead of thumbnail

We have a shop page on this website.
I will explain my problem using the very first image in the top left as example, although it applies to all of them.
If you hover over the first image (Gentes Deluxified English) you see an incomplete picture like this:
src= ".../Gentes-board-DLX-20180123-200x267.jpg"
This image actually cuts of parts of the images to the left and right. The full image is like this:
src= " .../Gentes-board-DLX-20180123.jpg"
So we want to change the thumbnail image to the full image, or keep the original ratio of the image. This needs to work for all images and the ones added in the future.
Is this fixable with css?
I already spent a lot of time looking at the source code of woocommerce to find the file that creates the page that uses the thumbnail images. I can't find that file. Where should I look for the source code files? And what should I change in these source files?
I looked at the source code of Woo commerce and found the parameter for cropping thumbnails for you.
https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-regenerate-images.php
Add this
$crop = false;
after line 318:
private static function get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop ) {

Display resized image programatically without creating another image on server

Is there any library or script which would allow me to display the resized version of an image programmatically? without actually creating another resized image and saving it into the server?
I am looking for something like this, ie:
<img src="script.php?image_path=/mysite.com/public_html/img/my_image.jpg&new_width=300&new_height=100" />
Is it possible? Does it exist?
I hope I am making sense here...
Thank you very much for your help! :o)
You can use Cloudinary to programmatically resize images based on the resolution of the viewing device. All you need to do is basically mention the height and width parameters and it transforms the image on-the-fly:
<?php echo cl_image_tag("my_image.jpg",
array("width" => 100, "height" => 150, "crop" => "fill"));
?>
For more examples on re-sizing that suit your specific use-case, you can refer the the documentation here:
http://cloudinary.com/documentation/php_image_manipulation#resize_crop_and_thumbnails

Cropping into an image in wordpress

Is it possible without messing with core to get WP to crop 'into' an image. So for example I have an image which is 800 x 800 and I would like it to crop it to 400 x400 by cropping top / bottom and left/right, in effect losing 200px off each side of the image.
In this example image. The cropping I am trying to achieve would give me a close-up of the mountains and part of the sun only.
Hoping not to reply on a plugin.Thnx
i think this function will help you.
<?php add_image_size( $name, $width, $height, $crop ); ?>

Wordpress select image size as PHP Variable

Wordpress creates a new image URL for each of the sizes of images it creates when an image is uploaded. It adds the image size in pixels to the end of the string before the image extension. The problem is that if say an image size for a medium image is 300x300, wordpress may crop it to say 300x180 to keep it in dimension.
This makes it difficult when programatically fetching a larger version of an image thumbnail as the file ending -300x300.jpg may not exist.
Is there a way of fetching the image by using the URL for the full image, with a PHP variable eg. ?size=medium on the end that will load the correct version. I'm sure I have done this with older versions of wordpress but cannot find any documentation to prove this.
From the documentation:
<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?>
$size
Either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32)
https://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
Add this to functions PHP so that the line above works for the first image if the post does not have a featured image.
function set_first_as_featured($attachment_ID){
$post_ID = get_post($attachment_ID)->post_parent;
if(!has_post_thumbnail($post_ID)){
set_post_thumbnail($post_ID, $attachment_ID);
}
}
add_action('add_attachment', 'set_first_as_featured');
add_action('edit_attachment', 'set_first_as_featured');
You can register a image size to use anywhere in your theme with add_image_size, see:
add_image_size( "your-custom-image-size", 300, 300, true );
then you can use in your theme as well:
the_post_thumbnail("your-custom-image-size", $attr);

Customized width and height in DOMPDF

Is there anyway i can set the generated PDF's width and height? i want to customized the width and height of the PDF. Normally it would be on a size of a short bond paper but how can i customized it? lets say for example i want it to be 200 x 500 pixel in size?
Any idea would be very much appreciated! cheers!
You can set your own format, without having to change DOMPDF code, by passing an array when you're calling DOMPDF::set_paper(). Make sure it contains the width and the height in points, like this:
$dompdf->set_paper(array(0, 0, 595, 841), 'portrait');
DOMPDF handles the paper size via the configuration.
define ("DOMPDF_DEFAULT_PAPER_SIZE", "letter");
You can referrer to all available sizes there:
https://github.com/dompdf/dompdf/blob/2eaf8fe0f1c95ab76e7a428a39a54dd240e2b2ec/src/Adapter/CPDF.php#L40

Categories