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 ); ?>
Related
Why does crop array in add_image_size() does not work properly unless the featured image is again uploaded?
Like here is the code
<?php add_image_size('banner-image', 920, 210, array('center','center')); ?>
This works perfectly for the first time but when I change the above code to
<?php add_image_size('banner-image', 920, 210, array('left','top')); ?>
It does not work on normal or hard refresh but image is cropped to left top when the featured image is again uploaded.
Any solution for this without cropping the image when uploading...
May i crop images in FPDF ?
i have try this one Cropping images in CodeIgniter for FPDF output but does not work
You can use clipping areas: http://www.fpdf.org/en/script/script78.php
With this extension you can define your visible area and output your image like this:
$pdf->ClippingRect($x, $y, $w, $h);
$pdf->Image($imageFile, $x - $imgOffsetX, $y - $imgOffsetY);
$pdf->UnsetClipping();
The whole image will be included in the pdf. If size matters, cropping the image file first can be the better way.
Sorry, you can not crop an image in FPDF. You must first crop the image before using it to create a PDF using FPDF. I can recommend doing this manually, or programmatically via ImageMagick. Then once you have your cropped jpg, gif or png, call Image.
$pdf->Image('croppedImage.png');
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
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
I need to resize an image to a defined width and height but crop the bottom to the height if it is larger or add blank space to the bottom if it is smaller. How to accomplish that with the help of PHP's GD?
I maid a function for this: PHP/GD Imagestyle
You can create thumbnails exactly as you described with the following:
$thumb = imagestyle($image,'autosize:100 100');
But also if you need something more complicated you can use:
// resize 200 0 means width=200 height=auto
$thumb = imagestyle($image,'resize:200 0; crop:200 200;');
You can use phpThumb library.
Take a look https://github.com/masterexploder/PHPThumb/wiki/Basic-Usage