Real cropping a PDF file - itext

In ghostscript-crop-pdf-not-correctly,I got a cropped PDF,but it's only seemingly cropped.The remaining content still exists in fact.
In ghostscript-removes-content-outside-the-crop-box or
how-to-truly-crop-a-pdf-file or pdf-real-cropping or cropping-a-pdf-using-ghostscript-9-01 or itext-crop-out-a-part-of-pdf-file, no solution was found.May be a virtual PDF printer is the only way.
Use ghostscript or itext, Is there any way to clip a PDF file really.

A very straightforward (but perhaps not the most intelligent) way of solving your problem is to use pdfSweep.
pdfSweep is an iText7 addon that allows you to redact (remove) content.
It allows you to remove content by:
specifying a regular expression
specifying a rectangle (or rectangles)
In your case, you could calculate the rectangles you want removed, and then apply pdfSweep.
If you then crop the remaining page, the content would really be gone.
More information (including code samples) can be found here.

What leads you to believe that the content is still present ?
Any object which is not at least partially contained within the page clip will not be forwarded on to the pdfwrite device by Ghostscript, so I'm doubtful that content is preserved.
Your original question related to cropping away white space, so that makes your example file less than useful in this case. You should post an example of the problem file, and the Ghostscript command line you have used.
Note that if you are trying to crop out an image then no, this won't do what you want. If any part of the image lies on the media, then the entire image will be included in the file. The pdfwrite device isn't equipped to extract sub-areas from images. This is true for all the PDF editors that I'm aware of.

Related

Covering Background Color in Crystal-Report went Adding Watermark

Why when adding a pic for watermark, always cover the detail background color?
I have tried with another type file. But it still same result. Anyone can help me?
Crystal-Report with example watermark
Crystal Reports doesn't have very good support for the transparent layer background of most image file formats. In almost all cases, images files are converted to a Bitmap image when they are used in a Crystal Report. This causes images to have a background that is slightly off compared to the color of the reports background. Underlay and moving the image behind other objects on the report help with most issues for the report's design, but you can never place the image behind the background.
There is a workaround for this using WMF or EMF files though. These are two image file formats that work in Crystal Report and support transparent layer backgrounds. If you don't have photo editing software that can produce WMF or EMF file, then there are two ways to do this without buying additional software. The first option is MS PowerPoint. If you insert the image into a PowerPoint presentation, then right click the inserted image, you can then choose Save As Picture and WMF and EMF are both available file types for this. The second option is a website called Zamzar. This website will allow you to convert files from one file type to another. Its a fairly fast service, but they have file size limits for free users.
Always keep in mind that the image will need to have a transparent background in the original file format before converting it to a WMF or EMF file. Also bear in mind that converting files from one type to another can sometimes have unintended implications upon the quality and detail of the images. Sometimes the best way to get a good quality image is to seek out the graphic designer who produced the image and request they provide the image in the WMF or EMF file types.

What are the differences between APNG and MNG?

I know that APNG is an extension of PNG, while MNG is more of its own format (albeit developed by the original PNG developers). MNG is barely supported in any browser at all, while APNG almost only has native support in Firefox (for various backward compatibility- and decoding-related reasons, it seems).
Except all of these behind-the-scenes things, what are the differences between APNG and MNG? Does one have features the other doesn't (for example, storing only parts that are modified instead of always whole frames)? Does one have better performance or file size than the other?
APNG can create a new frame by replacing the entire image or by overlaying or blending a smaller image over part of it. To display a "pong" game you'd need a new image of the ball in each different location. APNG has essentially the same capabilities as animated GIF, but also allowing 24bit RGB and 8-bit alpha.
MNG can do that, plus it can also retrieve an image that was previously defined in the datastream and place it over the previous frame in a new location. To display your "pong" game you'd only need to transmit one image of the ball and use it like a sprite.
Much more detail is available in the specifications:
apng: (https://wiki.mozilla.org/APNG_Specification‎)
mng: (http://www.libpng.org/pub/mng/spec/mng-lc.html)

Copy and pasting in Photoshop leaves transparent edge on image

I'm making cuts of an image to use in various parts of my website; The header, the footer, etc. When I copy and paste to a new layer, it leaves a "feathered" edge. even though I have this set to zero. There is a 1 pixel margin around all of the copy and pasted images, that, when assembled as a web page using CSS, leaves little lines between all of the images. I was a professional graphic designer but I've been out of the game too long (2 whole years). God help me.
I'm not 100% sure of the source of the initial assets such as the header and footer, so I'm a little confused (some links might be nice), however it is worth checking a few things just to make sure. Hit M for the marquee and check thats feather amount. L for the lasso (long shot) and check that too, also check for any layer styles.
A nice little alternative, if you are exporting out individual assets,is go to File > Scripts > Export Layers to Files. This may save you a lot of trouble in the long run.
Hopefully this may help...
Additionally how are you copying? Is it from inside Photsohop or are you placing the layers? Are you using the marquee tool?
for try, don't use crop tool.. use select tool instead. select tool provides pixel level accuracy.
In addition to feather, try turning off anti-aliasing in your selections. After you make a selection, in the select options toolbar uncheck 'Anti-alias'.
If this is set photoshop will try to average the edges of the selection with the surrounding pixels to make it 'blend' better. This is worse than useless if you're trying to make accurate, pixel-level selections.
In Photoshop CC, after selecting with the marquee tool, right click to access the Feather option. Enter 0.1 and then copy and paste. That should take care of it.
I just encountered this problem. I'd cut and pasted and then dragged into a new image which created a new layer with the paste on. I then realised that the feathering was wrong. I changed the settings but forgot to change the active layer back to the background layer, so I was cutting and pasting the feathered cut I did originally. Facepalm.

PIL convert('L') to greyscale distorts some images

I'm converting some images to greyscale with the easy-thumbnails Django app. Most of them are fine, but a handful are getting partially or totally messed up. The same error is occurring on two different machines, so I don't think it's an issue of a PIL install being corrupt or something.
Here are a couple examples:
Original image http://66.228.39.122/uploads/companies/alerts_logo.png Disorted version http://66.228.39.122/uploads/companies/alerts_logo.png.198x150_q85_bw_upscale.jpg
Original image http://66.228.39.122/uploads/companies/HashableLogo_Color_RGB.png Disorted version http://66.228.39.122/uploads/companies/HashableLogo_Color_RGB.png.198x150_q85_bw_upscale.jpg
Any suggestions? Are the original images themselves corrupt in some subtle way? Should I recompile PIL with --no-random-distort or something? I've looked at the relevant part of the easy-thumbnails source and it's just calling image.convert('L'), so I think the problem must lie either inside PIL or with the images themselves. the way the exclamation mark is distorted in the Alerts.com logo makes me think that perhaps there's some kind of encoding issue, since the outline of the exclamation mark is angled and its color appears to be contributing to a larger grey splotch...but the Hashable logo doesn't show quite the same problem. Maybe they are two different problems. Thanks for any suggestions/thoughts/advice.
Update: Actually, if I remove the bw filter and add instead replace_alpha="red" I get similar (though not greyscaled) distortions, so it looks like it is probably PIL unhappy with how the images are encoded or something. Unfortunately I need non-technical people to be able to upload new images and have them work, so a programmatic solution is necessary, rather than just resaving the images manually.
Update 2: I actually experimented a bit and found that resaving the PNGs with GIMP solves the problem, if I resave once and check the box for saving color information for transparent pixels, and then resave a second time with that box unchecked. Just doing the first or the second of these doesn't solve the problem, and doing both and then the first again re-causes it. And it still doesn't handle partial transparency well. Since this is tedious and imperfect, a programmatic solution would still be great if there are any PIL or PNG encoding whizzes out there.
Here is some code that will convert an image to grayscale, without losing quality.
from PIL import Image, ImageOps
image = Image.open('filepath')
image = ImageOps.grayscale(image)
image.save('filepath', quality=95)

How can I process an image to remove a watermark within my iPhone application?

I want to remove watermark from a picture within my iPhone / iPad application. Is there any kind of image processing I can perform within this application to do this?
Can't be done, sorry.
The watermarked image were originally two images (the base and the watermark), which were merged together to form the result. The problem here is that the most common image formats (such as JPG, PNG, or GIF) have no concept of layers - so that the base would be one layer, and the watermark another: the result is just one layer, onto which both were redrawn. This is somewhat similar to a physical painting: if you paint one image on a paper using watercolors, and then another over the same spot, their colors will mix and you won't be able to tell which parts belong to one or the other, as they'd become a single image.
This is similar with the computer image formats: there is only one "layer", which for every pixel encodes exactly one color that is there - only the current color exists, and the image doesn't keep track what was on that pixel before.
Now, the information is irreversibly lost from the result - in other words, it is not possible to recover the base knowing just the result (or the result and watermark) - BTW, that's exactly the point of watermarking.
I have borrowed the image sprites of StackOverflow for a demonstration; the actual images used are not unique, the technique would work just as well with any images. This was the watermark I used:
And this is the result image, after merging with the base:
Now, even though we have the exact watermark image used, there's no way to recover what was underneath that star in the original image. Through image processing operations, we could almost remove the star from the result, but there's not enough data to tell us what used to be underneath: - that information got erased in the merge at the beginning.
We could guess what used to be there, but then we're not doing recovery any more, we're interpreting the image and guessing what possibly could have been there - and that's pretty hard, even for a human; computers are really bad at that. This is the original image, before I watermarked it - I bet you were expecting something slightly different, no?
The watermark is almost certainly part of the image. (The only case in which it wouldn't be is something like PDF or SVG, where it could be a separate vector element.)
Watermarks are typically present on images for purposes of managing intellectual property; if one has licensed an image for a particular use, typically one will receive access to a version of the image without a watermark. Thus wanting to "remove watermarks" is also likely to be treated as highly suspicious.
Watermarks are part of the image, there isn't going to be a magic way to remove them and recover the missing pixels in any tool.
Take a look at the source! Most or the current watermarking is done in php as an automated script. In most cases you will see the base picture in source