Request Crop images
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| Inkscape |
Wishlist
|
jazzynico |
Bug Description
Hello,
I've got a request for a new feature in the next Inkcape version. I really miss a crop-tool for imported images. Could this tool be found in a next version please? Would be very nice!
Regards,
E. Komies
tags: | added: bitmap |
Changed in inkscape: | |
importance: | Undecided → Wishlist |
su_v (suv-lp) wrote : | #1 |
jazzynico (jazzynico) wrote : | #2 |
I've marked all the crop reports duplicate of #170291, except the newer ones.
Now that Inkscape has ImageMagick effects and that ImageMagick supports cropping, why not implementing a cropping extension (in Extensions>
Changed in inkscape: | |
assignee: | nobody → JazzyNico (jazzynico) |
status: | New → In Progress |
jazzynico (jazzynico) wrote : | #3 |
Here is a first try, using the bitmap extension system.
It crops a bitmap (or a selection of bitmaps) according to top, bottom, left and right values (in px).
The only drawback is that the bitmap is resized, but not its SVG element. Thus it works well if the height and width SVG attributes are not set. If they are, the image is cropped, but keeps its original size on canvas.
I see no way to resize the SVG element from the extension, except changing things in extension/
jazzynico (jazzynico) wrote : | #4 |
Jon, any idea or comment?
jazzynico (jazzynico) wrote : | #5 |
Oops, sorry Jon, I wanted to ask Ted...
Yeah, it wasn't really designed for that. What you could do is overload
the effect() function. Do the SVG tweeking, and then call the super
class's effect() function to do the image manipulation.
jazzynico (jazzynico) wrote : | #7 |
Thanks for the tip, Ted.
I've tried your suggestion, and I now have a new overloaded effect() function. The problem is that I need a Magick::Image to get the image size and it's Inkscape::XML::Node in order to tweak the height and size (which is not necessarily exactly the bitmap size, e.g. if the svg object is resized with the object handles). These elements are easily available from an ImageMagickDocC
An alternative solution consists in adding the node to the applyEffect function (could be interesting if we add other resizing effects), but it implies that we change all the existing bitmap extensions.
The solution may be obvious, but I'm not a C++ expert, and my last course is far in the past (I'm trying to understand Inkscape's code and learn C++ at the same time...).
Ted Gould (ted) wrote : | #8 |
What I'd recommend is using a member variable on your class. So then
you just save the node until you need it. So something like this:
MyClass::Effect
-> Sets MyClass::Working Node
-> Calls ImageMagic:
-> Clears MyClass::Working Node
ImageMagic:
-> Does IM magic.
-> Calls MyClass:
-> Cleans up IM stuff
MyClass:
-> Uses MyClass::Working Node
-> Adjusts bit map
-> Adjusts node
Does that make sense?
jazzynico (jazzynico) wrote : | #9 |
> Does that make sense?
Yes, thanks. But I wonder if we really need all that. All the bitmap work is done in Crop::applyEffect, and I could also scale the object directly in the ImageMagic::Effect loop. Here's what I've started to do (far from being finished...):
// Image size before effect
unsigned int cols_before = effectedImage.
unsigned int rows_before = effectedImage.
applyEffect
float cols_ratio = (float)rows_before / effectedImage.
float rows_ratio = (float)cols_before / effectedImage.
// The effect changed the image size, let's change the SVG height and width
if (cols_ratio != 1 and rows_ratio != 1) {
printf(", width reduced by %f\n", cols_ratio);
/*
// From transformation.cpp
SPItem *item = SP_ITEM(l->data);
Geom::Scale scale (0,0);
double new_width = scaleX;
if (fabs(new_width) < 1e-6) new_width = 1e-6;
double new_height = scaleY;
if (fabs(new_height) < 1e-6) new_height = 1e-6;
scale = Geom::Scale(
sp_item_
*/
}
jazzynico (jazzynico) wrote : | #10 |
Now I have to find a way to use sp_item_scale_rel inside ImageMagick:
I've started to copy a part of transformation.cpp which is not far from what I'm looking for. But I need to investigate more and understand how sp_items and all the related stuff work first...
Ted Gould (ted) wrote : | #11 |
On Wed, 2010-04-07 at 18:27 +0000, JazzyNico wrote:
> Yes, thanks. But I wonder if we really need all that. All the bitmap
> work is done in Crop::applyEffect, and I could also scale the object
> directly in the ImageMagic::Effect loop. Here's what I've started to do
> (far from being finished...):
Yeah, that works too. Always lots of choices in programming :)
jazzynico (jazzynico) wrote : | #12 |
> Yeah, that works too. Always lots of choices in programming :)
Yes, but not always simple and elegant. I'm not in the hurry, I'll try to do both :)
Changed in inkscape: | |
milestone: | none → 0.49 |
jazzynico (jazzynico) wrote : | #13 |
Back to this feature with a new patch.
I've added a postEffect method that can be called after the effect is applied. Its goal is to modify the item (an not the image) whenever it is needed (eg if the image element height and width needs to be modified).
Note: the crop dimensions are given in bitmap pixels and thus may differ from the canvas image dimension.
Please test and comment!
jazzynico (jazzynico) wrote : | #14 |
Available in the trunk as of revision 10554.
Changed in inkscape: | |
status: | In Progress → Fix Committed |
Changed in inkscape: | |
status: | Fix Committed → Fix Released |
bemyself (chxp-moon) wrote : | #15 |
Does the solution solve the problem that true crop in Inkscape?
I havenot see something about this in tuturiol.
Anyway, A true crop function is much help to reduce pdf format size when mix with bitmap and vector pictures, as the wishlist https:/
Qantas94Heavy (qantas94heavy) wrote : | #16 |
@bemyself: this is the Raster -> Crop extension I believe.
RFEs related to cropping bitmap images in Inkscape:
Bug #517082 “Request Crop images” (New)
Bug #479864 “image cutting tool like openoffice Draw” (New)
Bug #248199 “some image editing tools for webdesign” (Invalid)
Bug #172166 “PLEASE INKSCAPE ADD CROP” (Invalid)
Bug #171598 “Crop bitmaps” (Invalid)
Bug #171427 “Crop bitmaps” (Invalid)
Bug #171299 “adjust brightness, contrast and crop images in Inkscape” (Invalid)
Bug #170839 “crop image” (Invalid)
Bug #170514 “Inplace cropping of images” (Invalid)
Bug #170291 “Image Cropping” (Invalid)
I'm not sure if we can mark them all as duplicate (e.g. of 170291) because over the time masking, editing clippaths&masks, edit bitmap externally
- features have been added and improved:
clipping&
- importing of bitmaps has changed (from <image> to 'as pattern' back to <image> iiuc)
@JazzyNico - what would you suggest?