View Issue Details

IDProjectCategoryView StatusLast Update
0009799ScribusPDFpublic2021-01-25 00:33
Reportercezaryece Assigned Tojghali  
PrioritynormalSeveritytweakReproducibilityN/A
Status assignedResolutionopen 
Product Version1.4.0svn 
Target Version1.5.4 
Summary0009799: [PATCH] autocroping images during PDF export
DescriptionHere is patch for automatically crop JPG (and only JPG) images if they are manually scaled.
Patch is small but working well for me.

Maybe there should an option in PDF Export dialogue for switching this feature on/off - I am not good enough in GUI and Preferences tasks in Scribus.
Maybe my patch inspires somebody who improve it with GUI/Preferences and for other kind of files...
Tagspatch
PatchYes

Relationships

related to 0009790 new Include check of cropped images in pre-flight check 
has duplicate 0011393 closedjghali Export to PDF should trim images to frames 
has duplicate 0014115 closedjghali Option to crop images to frame in PDF document for smaller filesizes 

Activities

cezaryece

2011-03-04 11:18

developer  

autocrop_pdflib_core.patch (2,247 bytes)   
Index: Scribus/scribus/pdflib_core.cpp
===================================================================
--- Scribus/scribus/pdflib_core.cpp	(wersja 16339)
+++ Scribus/scribus/pdflib_core.cpp	(kopia robocza)
@@ -6702,6 +6702,7 @@
        bool   bitmapFromGS = false;
        bool   isEmbeddedPDF = false;
        bool   hasGrayProfile = false;
+	bool   cropped = false;
        QString profInUse = Profil;
        int    afl = Options.Resolution;
        double ax, ay, a2, a1;
@@ -6882,6 +6883,25 @@
                                        PDF_Error_ImageLoadFailure(fn);
                                        return false;
                                }
+
+
+				if (extensionIndicatesJPEG(ext) && c->ScaleType)
+				{
+					//autocropping only for JPG images (till now) and for images with manually scaling settings
+					double xs = sx * c->pixm.imgInfo.xres/72;
+					double ys = sy * c->pixm.imgInfo.yres/72;
+					double w = (c->width()/72) * c->pixm.imgInfo.xres / xs;
+					double h = (c->height()/72) * c->pixm.imgInfo.yres / ys;
+					QRect cropBox(-x, y, w, h);
+
+					QImage tempImage = img.qImage().copy(cropBox);
+					img = ScImage(tempImage);
+					x=0; y=0;
+					ImInfo.xa = x;
+					ImInfo.ya = y;
+					cropped = true;
+				}
+
                                if ((Options.RecalcPic) && (Options.PicRes < (qMax(72.0 / c->imageXScale(), 72.0 / c->imageYScale()))))
                                {
                                        double afl = Options.PicRes;
@@ -7170,7 +7190,8 @@
                        {
                                if (((Options.UseRGB || Options.UseProfiles2) && (cm == PDFOptions::Compression_Auto) && (c->effectsInUse.count() == 0) && (img.imgInfo.colorspace == ColorSpaceRGB)) && (!img.imgInfo.progressive) && (!((Options.RecalcPic) && (Options.PicRes < (qMax(72.0 / c->imageXScale(), 72.0 / c->imageYScale()))))))
                                {
-					jpegUseOriginal = true;
+					if (!cropped)
+						jpegUseOriginal = true;
                                        cm = PDFOptions::Compression_JPEG;
                                }
                                // We can't unfortunately use directly cmyk jpeg files. Otherwise we have to use the /Decode argument in image
autocrop_pdflib_core.patch (2,247 bytes)   

cbradney

2011-03-21 07:18

administrator   ~0025870

Assigning to Jean to review. I think I would prefer a ScImage::cropped(x,y,w,h) function than extra code in the PDF lib, so it can then be applied to all image types and the code can then be specific to image types as required.

cbradney

2012-06-14 21:30

administrator   ~0028138

Jean can you please test?

ale

2012-11-11 21:32

manager   ~0029190

double xs = sx * c->pixm.imgInfo.xres/72;
double w = (c->width()/72) * c->pixm.imgInfo.xres / xs;

is the same as

w = c->width()/sx;

(where sx is c->imageXScale())

JLuc

2013-05-09 10:07

developer   ~0030144

That would be great and contribute to have slightly lighter PDFs.

Kunda

2015-11-13 21:55

updater   ~0037465

Balpha also made a patch for this issue. It's in his bitbucket

dogil

2016-05-29 02:35

reporter   ~0041504

Does this work with images that have a rotation inside the frame?

dogil

2016-05-29 03:21

reporter   ~0041513

How can I test this? It's over five years old...

oberten

2021-01-24 20:12

reporter   ~0048751

This is still useful, isn't it?

dogil

2021-01-25 00:33

reporter   ~0048753

I think it is. For two reasons:
1. It will result in smaller PDFs when small crops of large source images are used. In some cases you may then email documents which were too large before.
2. There are privacy implications if the document publisher crops out a person - let's say a child - from an image, but the receiver of the PDF can simply extract the full image from the document sources.

Issue History

Date Modified Username Field Change
2011-03-04 11:18 cezaryece New Issue
2011-03-04 11:18 cezaryece File Added: autocrop_pdflib_core.patch
2011-03-21 07:14 cbradney Assigned To => jghali
2011-03-21 07:14 cbradney Status new => assigned
2011-03-21 07:18 cbradney Note Added: 0025870
2011-04-16 09:26 cbradney Target Version => 1.5.0
2012-06-14 21:30 cbradney Note Added: 0028138
2012-11-11 21:32 ale Note Added: 0029190
2013-01-23 07:03 jghali Relationship added has duplicate 0011393
2013-05-09 10:07 JLuc Note Added: 0030144
2014-04-04 15:16 JLuc Tag Attached: patch
2014-07-03 19:32 Kunda Target Version 1.5.0 => 1.5.1
2014-10-24 23:00 Kunda Patch => Yes
2015-11-13 21:55 Kunda Note Added: 0037465
2016-01-23 17:17 cbradney Target Version 1.5.1 => 1.5.3
2016-05-28 20:25 jghali Relationship added has duplicate 0014115
2016-05-29 02:35 dogil Note Added: 0041504
2016-05-29 03:21 dogil Note Added: 0041513
2016-05-29 08:06 Kunda Relationship added related to 0009790
2016-12-08 22:04 Kunda Target Version 1.5.3 => 1.5.4
2021-01-24 20:12 oberten Note Added: 0048751
2021-01-25 00:33 dogil Note Added: 0048753