ImageMagick doesn't transform images in portrait (vertical) orientation - imagemagick

I'm making images transformation in TYPO3, cropping and resizing with ImageMagick.
When the orientation is horizontal, all is working fine, when the image orientation is portrait (vertical), the system doesn't generate images at all.
There is empty result at the place of generated image link.
Images in landscape (horizontal) orientation generates flawlessly.
TypoScript code, which contains image processing data :
...
image {
file.width = 600c
file.height = 500c
}
...
ImageMagick package info (CentOS 5.7) :
Name : ImageMagick
Arch : x86_64
Version : 6.2.8.0
Release : 4.el5_5.3
The same behaviour I saw on Windows 7 installation with ImageMagick 6.7.2
Probably it's related to default ImageMagick configuration ?
Does anybody saw such strange ImageMagick / TYPO3 behavior ?

Found : the situation was related to the issue of ImageMagick, when the result width size was bigger than default image width.
So, You should use maxW instead width in Your configuration and maxH instead of height.
Example :
...
image {
file.maxW = 600c
file.maxH = 500c
}
...

Related

ARKit reference image loaded at different size than in Assets

I am running the sample project for ARKit and I am trying to add my own image. There is a weird behaviour as the image is loaded at a different size than set in the asset inspector:
As can be seen, the image is (almost) an A5 size (14.8 x 19.7 cm), but it is loaded by ARKit at 14.8 x 11.1 cm. The metadata of the picture also has a height greater than the width: 3024 x 4032. The image is a jpg.
To be noted, there are no changes made in the code from the sample project from Apple which I am currently running.
Another note, the app detects the image successfully, but the detected area on the piece of paper is clipped to the dimensions printed in console.
A third note: I observed that the 11.1 cm dimension would be obtained if the image would be rotated 90 degrees (i.e. consider the height to be 14.8 cm, then the width would be 11.1 cm). This looks weird enough as nothing points to anything like that. I also double checked my image, but there seems nothing wrong with it.
The question is: is there anything I am missing or things I have to consider/do with my sample image? Is this a known issue or is there any workaround to make ARKit load my image with the expected dimensions?
Update
The source of the Apple's sample project: https://developer.apple.com/documentation/arkit/detecting_images_in_an_ar_experience
An extra side note: I only experienced this issue with a single image file. It was an image taken by an iPhone and converted from HEIC to jpg using an online converter (which I cannot find anymore). Anyway, the image file did not seem to have any anomalies.

Xcode #2x image suffix not showing as Retina in iOS

I am having difficulties with retina images.
The screenshot below shows the UICollectionView with a UIImageView contained within each UICollectionViewCell.
Within the app I have a large image 512x512 pixels called travel.png.
The green circle shows what is displayed on the app when I name this file: travel.png. The blue circle shows what I see when I update the image name to be travel#2x.png (i.e. retina naming).
I was hoping due to the large size of the image (512x512) that simply adding the #2x suffix would be enough to convert it to twice the definition (i.e. retina) but as you can see from the two screenshots, both version images show as non-retina.
How can I update the image so that it will display in retina?
travel.png:
travel#2x.png:
* Updated *
Following request in comments below:
I load this image by calling the following function:
// Note - when this method is called: contentMode is set to .scaleAspectFit & imageName is "travel"
public func setImageName(imageName: String, contentMode: ContentMode) {
self.contentMode = contentMode
if let image = UIImage(named: imageName) {
self.image = image
}
}
Here is how the image appears in Xcode before the app renders it (as you can see it is high enough definition):
The reason why you see the low quality image is anti-aliasing. When you provide images bigger then an actual frame of UIImageView (scaleAspectFit mode) the system will automatically downscale them. During scaling some anti-aliasing effects can be added at curve shapes. To avoid the effect you should provide the exact image size you want to display on the screen.
To detect if UIImageView autoscale the image you can switch on Debug->Color Misaligned Images at Simulator menu:
Now all scaled images will highlight at simulator with yellow color. Each highlighted image may have anti-aliasing artifacts and affect CPU usage for scaling algorithms:
To resolve the issue you should use exact sizes. So the system will use them directly without any additional calculations. For example, if your button have 80x80px size you should add three images to assert catalog with following sizes and dpi: 80x80px (72 dpi), 160x160px (144 dpi) and 240x240px (216 dpi):
Now the image will be drawn at the screen without downscaling with much better visual quality:
If your intention is to have just one image for all the sizes, I would suggest it having under Assets.xcassets. It is easy to create the folder structures and manage media assets here.
Steps
On clicking + icon, you will displayed a list of actions. Choose to create a New folder.
Choosing the new folder that is created, click on the + icon again and click on New Image Set.
Choose the imageset. And choose the attributes inspector.
Select Single Scale, under Scales.
Drag and drop the image.
Rename the image name and folder names as you wish.
Now you can use this image using the image name for all the screen sizes.
TL;DR;
Change the view layer's minificationFilter to .trilinear
imageView.layer.minificationFilter = .trilinear
as illustrated by the device screenshot below
As Anton's answer correctly pointed out, the aliasing effet you observe is caused by the large difference in dimensions between the source image and the image view it's displayed in. Adding the #2x suffix won't change anything if you do not change the dimensions of the source image itself.
That said there is an easy way to improve the situation without resizing the original image: CALayer offers some control over the method used by the graphics back-end to resize images : minificationFilter and magnificationFilter. The first one is relevant in your case since the image size is being reduced. The default value is CALayerContentsFilter.linear, just switch to .trilinear for a much better result (more info on those wikipedia pages). This will require more GPU power (thus battery), especially if you apply it on many images.
You should really consider resizing the images before displaying them, either statically or at run-time (and maybe cache the resized versions). In addition to the bad visual quality, using such large images in quantities in your UI will decrease performance and waste lots of memory, leading to potentially other issues.
I have fixed, #DarshanKunjadiya issue.
Make sure (if you are already using assets):
Make sure images are not un-assigned
Now use images in storyboard or code without extensions. (e.g. "image" NOT "image.png")
If you are not using images from assets, move them to assets.
Demo Projects
Hope it helps.
Let me know of your feedback.
I think images without the #2x and #3x are rendered for devices with low resolutions (like the iphone 4 an 3G).
The solution I think is to always use the .xcassets file or to add the #2x or #3X in the names of your images.
In iOS, content is placed on the screen based on the iOS coordinate system. for displaying an image on a standard resolution system having 1:1 pixel density we should supply image at #1x resolution. for higher resolution displays the pixel density will be a scale factor of 2.0, 3.0 which refers in the iOS system as #2x and #3x respectively. That is high-resolution displays demands images with higher density.
For example, if you want to display an image of size 128x128 in standard resolution. You have to supply the #2x and #3x size image of the same. ie., 256x256 at #2x version and 384x384 image at #3x version.
In the following screenshot, I have supplied an image of size 256x256 for 2x version to display a 128x128 pixel image in iPhone 6s. iPhone 6s render images at #2x size. Using the three version of images such as 1x, 2x and 3x with asset catalogue will resolve your issues. So the iPhone will automatically render the correct sized image automatically with the screen resolution.

Why is UIImage rotated after being initialised from asssets?

I have an image in my xcassets folder which is in PDF format and I init and assign to an UIImageView this way:
imageView.image = UIImage(named: "myImage", in: Bundle.current, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
When I run the app, this image is displayed rotated/flip, but I'm not rotating it in code. The image file looks ok. What could it be happening there?
I had the same issue which is completely ununderstandable. But it only happened to a tiny rectangular vector image oriented vertically, placed in xcassets. I tried a few things like changing all the settings xcasset gives us. Alas, the only thing that worked for me was to increase the image size. Then iOS stopped changing the orientation.
It really looks like a bug from xcode trying to compress/optimize images and mistakenly rotate images...
Anyway, try to change the image size (scale it up - or insert margins). Also, try to export to another media type.

How Do I Change Output Resolution On Existing Image With RMagick/ImageMagick?

ImageMagick and RMagick both have a setting/attribute for "density", which is what they call resolution. I can pass it a value of 200 and it should set the resolution to 200x200 when the image is written to either a file or to_blob.
In the Rails console I can load the image, then set the density, and if I check it, it will tell me the density (originally 300x300) is now 200x200, but when I write it out to a file, the resolution is 300x300.
The only way I've successfully been able to change the resolution is by creating a new image of the same width and height, then overlay the original image. This, however, distorts the output, no matter what settings I use (I tried setting the original to fully opaque, the "new" to fully transparent, and even used the CopyCompositeOperation, which should fully replace the "new" image).
I have tried setting density like this:
image.density = "200"
And like this
image.write("test.jpg") {self.density="200"}
And both.
Nothing works... any ideas?
To be clear... I don't want to resize the image, I want to change the print resolution. I want the dimensions to remain the same (i.e. width/height should NOT change).
This was an issue with the version of ImageMagick that AWS has in its repositories. Removing that version and installing from source made the density setting work. Also, if you want the resolution change to be reflected in Windows applications, you need to strip the "8bim" profile from the image:
image.profile!("8bim",nil)

How can I scale an image with ColdFusion without losing resolution?

Server Config:
Windows Server 2003
IIS 6
ColdFusion 8 Standard Edition
Java Version 6 Update 18
I have a ColdFusion application that allows users to upload images that will be added to an existing PDF. When the images are added to the PDF, they have to fit within a minimum/maximum height and width, so the uploaded image needs to be scaled to fit.
For instance, let's say the minimum height and width for a given image is 100x100, and the maximum height and width is 200x200, and the user uploads an image that is 500x1000. I use the logic below to scale that image down without skewing the image (it keeps its original shape) to 100x200. For an image smaller than the minimum, it is scaled up (in the example above, a 50x50 image would be scaled up to 100x100).
The problem I'm noticing is that when ColdFusion scales the image using its built-in functions, it reduces the resolution to 72dpi. Is there a way to prevent this loss of resolution, as the images are being added to PDFs which need to be print-quality?
Here's the [scaled-down] code I'm using to scale the images:
<cfscript>
imagePath = "/uploads/image.tif";
scaledWidth = 100;
scaledHeight = 100;
scaledImage = ImageNew(imagePath);
ImageSetAntialiasing(scaledImage, "on");
ImageScaleToFit(scaledImage, scaledWidth, scaledHeight);
</cfscript>
I think you may want to skip scaling the image at all and add the original image to the pdf document. Then have whatever pdf creation tool you are using "resize" and position the image on the document canvas. Similar to setting width and height on images in html to something other than its native resolution. I have not had to add images to PDFs docs like you described but this post might point you in the right direction:
Adding a dynamic image to a PDF using ColdFusion and iText

Resources