Comments (15)
It is not a defect. It would be kind of an improvement I think, but I do not
know how to change the type of the issue.
Cheers.
Original comment by [email protected]
on 13 Oct 2011 at 8:14
from thumbnailator.
Sorry for the late reply.
Let me see if I understand your request correctly.
You'd like to see a feature where one would be able to:
1. define the minimum dimensions that the thumbnail should resize to, then
2. crop out a portion of the resized image to the dimension you desire
With a concrete example -- starting from a 400x600 image, we want to end up
with a final image of 200x200.
1. The first step should resize the image so the image will be at least 200x200, so the resized image will be 200x300.
2. The second step will be to crop out a 200x200 region of the 200x300 image.
Please let me know if this is what is being requested.
----------
Notes by the developer about the potential API design.
Candidate 1:
Thumbnails.of("path/to/image")
.minimumSize(200, 200)
.crop(Positions.CENTER)
.toFile("path/to/thumbnail");
* Use the `minimumSize` method currently being proposed for Issue 22.
* The downside is that it is unintuitive.
or
Thumbnails.of("path/to/image")
.size(200, 200)
.crop(Positions.CENTER)
.toFile("path/to/thumbnail");
* This would be more intuitive.
* However, the behavior of the `size` method will be overriden so that the image will no longer be resized to be a *maximum* of 200x200, but it will be sized so that the minimum dimension will be 200x200.
Another potential design consideration is whether to have dimension arguments
on the `crop` method, i.e. `crop(int width, int height, Position position)`
Original comment by [email protected]
on 29 Oct 2011 at 3:32
from thumbnailator.
Original comment by [email protected]
on 29 Oct 2011 at 3:32
- Added labels: Type-Enhancement
- Removed labels: Type-Defect
from thumbnailator.
Yes. Your examples are perfect.
This is exactly what I meant.
About the "crop" function: I think it would be a great improvement too.
Thanks for you reply.
And, again, congratulations for your work. Thumbnailator is a great library.
Original comment by [email protected]
on 29 Oct 2011 at 3:42
from thumbnailator.
Thank you for your kind words. :)
Comments like your's have made working on Thumbnailator very worthwhile and
rewarding. Thank you!
Original comment by [email protected]
on 13 Nov 2011 at 6:17
from thumbnailator.
Exactly the feature I'm looking for as well. Look forward to seeing the
updates. Thanks!
Original comment by [email protected]
on 15 Nov 2011 at 12:56
from thumbnailator.
Hi,
I had this requirement too .. This can be done now as follows:
//required dimensions of thumb
dw = ?
dh = ?
double da = dw / dh;
//get orig
BufferedImage orig = ImageIO.read(new File("origimage"));
int sw = orig.getWidth();
int sh = orig.getHeight();
double sa = sw / sh;
BufferedImage thumb = null;
// crop? and scale
if (sa > da) {
// too wide
double tw = sh * da;
int x = (int) (sw - tw) / 2;
int y = 0;
thumb = Thumbnails.of(orig).sourceRegion(x, y, (int) tw, sh)
.size(dw, dh).asBufferedImage();
} else if (sa < da) {
//too tall
double th = sw / da;
int x = 0;
int y = (int) (sh - th) / 2;
thumb = Thumbnails.of(orig).sourceRegion(x, y, sw, (int) th).size(dw, dh).asBufferedImage();
} else {
//same aspect ratio ... scale
thumb = Thumbnails.of(orig).size(dw, dh).asBufferedImage();
}
if(thumb != nul){
...
}
Original comment by [email protected]
on 20 Jan 2012 at 11:58
from thumbnailator.
Hello,
Thanks for your reply!
I'm on vacation now, but I'll try it soon as possible.
Regards,
Luan Mattner Müller
Original comment by [email protected]
on 3 Feb 2012 at 4:44
from thumbnailator.
Original comment by [email protected]
on 5 Feb 2012 at 8:12
- Changed state: Accepted
- Added labels: Milestone-0.4.x
from thumbnailator.
Original comment by [email protected]
on 5 Feb 2012 at 5:20
- Changed state: Started
from thumbnailator.
This issue has been addressed by the addition of the `crop` method in
Thumbnailator 0.4.0:
http://thumbnailator.googlecode.com/hg/javadoc/net/coobird/thumbnailator/Thumbna
ils.Builder.html#crop(net.coobird.thumbnailator.geometry.Position)
For example, resizing a image to 100x100 while cropping out the center portion
of the image, one can use the following code:
Thumbnails.of("path/to/image")
.crop(Positions.CENTER)
.size(100, 100)
.toFile("path/to/thumbnail");
For a visual representation of what takes place, please take a look at the
image presented in the "Changes" page for the Thumbnailator 0.4.0 release:
http://code.google.com/p/thumbnailator/wiki/Changes#Thumbnailator_0.4.0_(Februar
y_11,_2012)
Original comment by [email protected]
on 11 Feb 2012 at 7:15
- Changed state: Fixed
- Added labels: Milestone-0.4.0
- Removed labels: Milestone-0.4.x
from thumbnailator.
That's perfect!
I will try this new functionality soon as possible!
Thanks for the attention on this issue!
Best regards,
Luan Mattner Müller
Original comment by [email protected]
on 11 Feb 2012 at 7:22
from thumbnailator.
Thank you + 1
Original comment by [email protected]
on 11 Feb 2012 at 7:27
from thumbnailator.
I don't want to keep aspect ration how can I acheive that.
// gives me image with aspect ratio.
//Input image dimension 1366x768
BufferedImage img = Thumbnails.of(bufferedImage).size(65, 65).asBufferedImage();
// getting image of 65x37
//saving it by
save(new File(loc), img);
public void save(File file, BufferedImage image2) {
this.filename = file.getName();
String suffix = filename.substring(filename.lastIndexOf('.') + 1);
suffix = suffix.toLowerCase();
if (suffix.equals("jpg") || suffix.equals("png") || suffix.equals("gif")) {
File f2 = new File(file.getPath());
if (f2.exists() == false) {
f2.mkdirs();
}
if (file.exists()) {
file.delete();
}
try {
ImageIO.write(image2, suffix, file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("Error: filename must end in .jpg or .png");
}
}
Original comment by [email protected]
on 27 Dec 2014 at 11:16
Attachments:
from thumbnailator.
Hello DevOrg,
Trying to deduce your intent from the attached image, I'm guessing that you do
indeed want to keep the aspect ratio of the original image, but want to have it
cropped in the center so that the final image will be 65x65.
In order to do so, you can use the `crop` method, such as:
BufferedImage img =
Thumbnails.of("path/to/image")
.size(65, 65)
.crop(Positions.CENTER)
.asBufferedImage();
By doing the above, you'll be able to end up with an image which is similar to
the thumbnail images shown at the bottom of the attached picture.
I hope that's what you're trying to achieve.
Also, in the future, if you have a question or an issue, please open a new
issue, as that would be a more appropriate place to address your issue than to
add to a feature-request ticket which has been closed 3 years ago -- Thank you!
Original comment by [email protected]
on 10 Jan 2015 at 8:41
from thumbnailator.
Related Issues (20)
- How to ensure the GIF dynamic effect after compression HOT 1
- Do you have plans to support WebP, AVIF? HOT 1
- Thumbnail not properly generating from PNG images HOT 2
- Image color loss during conversion HOT 3
- Define an Automatic-Module-Name HOT 1
- the image format webp is not support HOT 5
- No suitable ImageReader found for source data errors HOT 1
- After resize the image is rotated HOT 3
- 300dpi tiff image changed to 96pi jpg but pixel does not chage HOT 1
- Incorrect cropping when specifying sourceRegion and an image that has exif orientation HOT 2
- Multi-threaded processing of images with large pixel width and height leads to memory OutOfMemoryError
- the .pict file is not supported HOT 1
- javax.imageio.IIOException: Invalid JPEG file structure: two SOF markers HOT 1
- Add crop method usage to examples HOT 2
- How to make the image width fixed when the image is scaled HOT 1
- Does the thumbnailator support generating thumbnails for png images? HOT 1
- Conversion error caused by image reading failure
- Native image service unable to compress image
- jpg color turn red HOT 2
- webp format image campress fail with exception "No suitable ImageReader found for source data" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thumbnailator.