How to STOP Trimming

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

How to STOP Trimming

Post by dmfelder »

I have a 4" x 4" canvas with a 3" x 3" image within it. In other words, there is a 1/2" transparent border around the entire layer. It is a PSD, and I am converting it to a smaller PNG.

I have tinkered with two different operations:

objMi.Convert "-resize", "400x400", myimagename1, tempimagename
objMi.Convert "-background", "none", "-layers", "merge", myimagename1, tempimagename

In each case, the operation is trimming the resulting image. I do not want to trim this image. It should maintain the proportional border. Am I doing something wrong?

Thanks for any help you guys can provide.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to STOP Trimming

Post by snibgo »

Perhaps PS has created the image within a larger canvas, and "-layers flatten" will extend the image to the canvas.
snibgo's IM pages: im.snibgo.com
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Re: How to STOP Trimming

Post by dmfelder »

In fact, just the basic

convert myPSDimage, myPNGimage

is trimming it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to STOP Trimming

Post by fmw42 »

Can you post a link to your psd image? You can upload to dropbox.com (public folder) and put a link here. Then we can see what your input image is like and test with it.

Also what version of IM and what platform are you using?
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Re: How to STOP Trimming

Post by dmfelder »

I uploaded the PSD to: greatapparelforyou.com/tempimage.psd

It's difficult for me to know which version I'm working with because I'm using it in a unique way (VBA within Microsoft Access), and without a console. I have been using IM successfully within this realm for over a year, though. Ironically, historically, I've always wanted to trim.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to STOP Trimming

Post by glennrp »

Your file actually contains two images, one fullsize and one trimmed.
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Re: How to STOP Trimming

Post by dmfelder »

I know you guys are very smart, so I will reluctantly accept what you say. :)

However, when I open it in Photoshop, it only has one layer.

Also, I was experimenting with the following code which would have merged them anyway: objMi.Convert "-background", "none", "-layers", "merge", myimagename1, tempimagename

Thoughts?

How can I reveal both layers?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to STOP Trimming

Post by snibgo »

As glenrp says, IM can see two images. Take your pick which one you want.

Code: Select all

F:\web\im>%IM%convert tempimage.psd info:
tempimage.psd[0] PSD 1200x1200 1200x1200+0+0 8-bit CMYK 581KB 0.281u 0:00.062
tempimage.psd[1] PSD 1040x968 1040x968+80+116 8-bit CMYK 581KB 0.359u 0:00.078

F:\web\im>%IM%convert tempimage.psd[0] p0.png

F:\web\im>%IM%convert tempimage.psd[1] p1.png
snibgo's IM pages: im.snibgo.com
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Re: How to STOP Trimming

Post by dmfelder »

That is truly remarkable. The image was created in Photoshop, too, as a single layer.

Thank you all for the input. I think using the [0] will work; although, I wonder if the [0] layer will always be the full size image in the event this happens again. Time will tell.

Cheers.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to STOP Trimming

Post by fmw42 »

When I download your image, it shows only one layer in IM 6.8.8.10 Q16 Mac OSX and Photoshop. Photoshop CS shows no oddities that I can see.


identify tempimage.psd
tempimage.psd PSD 1200x1200 1200x1200+0+0 8-bit CMYK 581KB 0.010u 0:00.000

Oddly, when I do the following, I get two identical png images (both the same size)

Code: Select all

convert tempimage.psd -trim +repage tmpimage.png
Likewise when converting your cmyk image to srgb.

Code: Select all

convert tempimage.psd -colorspace sRGB  -trim +repage tmpimage2.png
And also when converting to RGB in Photoshop and saving, it still produces two png output images.

Saving the latter to tiff, produces an image with 2 layers as does saving to jpg. But saving to PPM produces only one image.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: How to STOP Trimming

Post by dlemstra »

It is correct that you are seeing two images. The first image is the 'merged' image that combines all the layers. The second image is the single layer that this image contains. And yes you should use tempimage.psd[0] to get the image with the transparent border.
Last edited by dlemstra on 2014-04-07T15:35:08-07:00, edited 1 time in total.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to STOP Trimming

Post by fmw42 »

dlemstra wrote:It is correct that you are seeing two images. The first image is the 'merged' image that combines all the layers. The second image is the single layer that this image contains.
You are probably right about that. I forgot that IM would create the flattened layer whether there was one layer or not.

But then it is strange that when converting to PPM, I do not get two output images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to STOP Trimming

Post by snibgo »

On 6.8.8-7 on Windows 8.1, I do get two images in the PPM file.

Code: Select all

convert tempimage.psd -compress none p.ppm
Looking at p.ppm, I can see where the second image starts at "P3".
snibgo's IM pages: im.snibgo.com
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: How to STOP Trimming

Post by dlemstra »

PPM supports multiple images in one file:

Code: Select all

D:\Test\psd>identify tempimage.ppm
tempimage.ppm[0] PPM 1200x1200 1200x1200+0+0 8-bit sRGB 7.34MB 0.031u 0:00.029
tempimage.ppm[1] PPM 1040x968 1040x968+0+0 8-bit sRGB 7.34MB 0.016u 0:00.018
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to STOP Trimming

Post by fmw42 »

PPM supports multiple images in one file:
Thanks. I forgot about that.
Post Reply