automatic imagescaling with image or graphicmagick - imagemagick

I've got a question that depends on imagemagick:
Is it possible to upload just one picture with a size of 1200px height for example and -depending on device or browser resolution- reduce the imageheight AND size of the image?
Thanks in advance

You can use conditions depending on devices or browser versions. Assuming you like to switch between the folling image heights:
600px for IE6,
320px for mobile devices,
800px for all other devices
(i.e. regular computers)
Then enter this section to your template constants:
# for IE6:
[browser = msie] AND [version = 6]
styles.content.imgtext {
maxH = 600
maxHInText = 600
}
# for mobile devices:
[useragent = *iPhone*]||[useragent = *iPod*]||[useragent = *Android*]||[useragent = *OperaMini*]||[useragent = *BlackBerry*]
styles.content.imgtext {
maxH = 320
maxHInText = 320
}
# For all other browsers
[else]
styles.content.imgtext {
maxH = 800
maxHInText = 800
}
[GLOBAL]
Alternative solution for template setup (explained below):
# for IE6:
[browser = msie] AND [version = 6]
tt_content.image.20.1.file {
maxH = 600
maxHInText = 600
}
# for mobile devices:
[useragent = *iPhone*]||[useragent = *iPod*]||[useragent = *Android*]||[useragent = *OperaMini*]||[useragent = *BlackBerry*]
tt_content.image.20.1.file {
maxH = 320
maxHInText = 320
}
# For all other browsers
[else]
tt_content.image.20.1.file {
maxH = 800
maxHInText = 800
}
[GLOBAL]
These are just some examples of conditions. Check out the TYPO3 conditions
reference for more ideas.
If the recognition of mobile devices does not work correctly with useragent, try the extension cwmobileredirect. It provides a very reliable mobile device switch.
This is about how to set the image height. I heard rumours that setting the width (maxW) works fine, but setting the height (maxH) is buggy somehow in versions below 4.2. Use the alternative solution if problems with maxH occur.

Related

iOS 11.3 ARKit Autofocus and higher resolution

As mentioned here Apple is allowing us to use higher resolution and Autofocus in the apps based on ArKit, have anybody already tried implementing those features in own apps ?
Where apple is usually sharing more technical details about such updates ?
Regards !
You haven’t been able to set the ARCamera image resolution... which is why you may not find anything relating to adjusting the camera image resolution. Changing ARCamera Resolution
If you want to check the ARCamera image resolution you can do so access via the currentFrame.
let currentFrame = sceneView.session.currentFrame
print(currentFrame?.camera.imageResolution)
to date it was set to 1280.0, 720.0
if you want more information about focal-length, which i believe auto-focus may now be able to adjust automatically. You can just check the camera property of currentFrame.
print(currentFrame?.camera)
Ok, autofocus can be added with:
var isAutoFocusEnabled: Bool { get set }
var configuration = ARWorldTrackingConfiguration()
configuration.isAutoFocusEnabled = true // or false
Any clues what about higher res ?
I am able to select desired resolution for AR camera using following code -
ARWorldTrackingConfiguration* configuration = [ARWorldTrackingConfiguration new];
NSArray<ARVideoFormat*>* supportedVideoFormats = [ARWorldTrackingConfiguration supportedVideoFormats];
int bestFormatIndex = 0;
for (int i = 0; i < [supportedVideoFormats count]; i++) {
float width = supportedVideoFormats[i].imageResolution.width;
float height = supportedVideoFormats[i].imageResolution.height;
NSLog(#"AR Video Format %f x %f", width, height);
if (width * 9 == height * 16) { // <-- Use your own condition for selecting video format
bestFormatIndex = i;
break;
}
}
[configuration setVideoFormat:supportedVideoFormats[bestFormatIndex]];
// Run the view's session
[_mSceneView.session runWithConfiguration:configuration];
For my requirement I wanted biggest 16:9 ratio. On iPhone 8+, following image resolutions are getting listed -
1920 x 1440
1920 x 1080
1280 x 720
Notice that they are sorted in the supportedVideoFormats array, with biggest resolution at 0 index. And 0th index is the default selected video format.

how to dynamically scale a screen in coronasdk

my current config file is for ipad retina and it works perfectly, however when i select a device with a smaller screen the image becomes warped.
here is my current config.lua
application = {
content = {
width = 768,--aspectRatio > 1.5 and 800 or math.ceil( 1200 / aspectRatio ),
height = 1024,
scale = "none",
fps = 60,
imageSuffix = {
["#2x"] = 1.3,
}
}
}
i would like to know if there is a way to dynamically set the width or height without hardcoding these figures for each invdividual device.
I use letterbox scaling for that.
application =
{
content =
{
width = 320,
height = 480,
scale = "letterbox",
xAlign = "center",
yAlign = "center",
imageSuffix =
{
["#2"] = 1.8,
["#4"] = 3.6,
},
},
}
Then I can use display.newImageRect, provided with dimensions of image for 320,480 device resolutions. #2 and #4 image suffixes are images 2x and 4x bigger.
Here is excellent article to get you in the corona scaling features:
http://coronalabs.com/blog/2010/11/20/content-scaling-made-easy/
I suggest you read this article about "the ultimate config/modernizing the config".
Some screens are wider while others are more narrow. If we take
resolution out of the equation, its easier to visualize the screens.
Corona makes it easy to take resolution out of the picture using
Dynamic Scaling. With Dynamic Scaling, you can use a common set of
screen coordinates and Corona will automatically scale the text and
graphics for different resolution screens. It can scale upwards or
downwards depending on your starting point. It also can substitute
higher resolution images when it needs to scale up. This is all
managed by a Lua file in your project folder called config.lua.
Since available resolutions vary considerably, it’s helpful to use the
same scale for each device. It doesn’t matter if you’re on an iPhone
3GS at 320×480 or a Retina iPad at 1536×2048, the location (0,0)
represents the top-left corner and (320,480), in vertical portrait
mode, is the bottom-right corner. The screen center is (160,240).
Each point, in this case, is one pixel on a lower-resolution device
like the 3GS, which has a native screen resolution of 320×480, while
each point is four pixels on a Retina iPad. Don’t worry about the math
— Corona will handle it for you.
Source: http://coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/
local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio ),
height = aspectRatio < 1.5 and 480 or math.ceil( 320 * aspectRatio ),
scale = "letterBox",
fps = 30,
imageSuffix = {
["#2x"] = 1.3,
},
},
}

How can we set height and width of the device in basis of device in corona

I found a issue that i set height and width in config .lua file as 960 * 640. When i run this app on other device which has high resolution that the above said, it got stretched. How can we set height and width in config.lua on the basis of which device it runs?
config.lua:
application = {
content = {
width = 640,
height = 960,
scale = "letterBox",
fps = 30,
imageSuffix = {
["-sd"] = 0.5,
[""] = 1,
["-hd"] = 1.4,
["-hdpi"] = 0.7
}
}
}
From now on your image.png will be displayed on every 640x960 screen. You should also include 3 additional images for other screens:
image-sd.png for screens 50% smaller than 640x960
image-hd.png for screens 140% bigger than 640x960
image-hdpi.png for screens 70% size of 640x960
Keep in mind, that you have to use only image.png in all the code. Suffix is added automatically according to what you set in config.lua

Easier/correct way to resize elements according to screen size

I've got an iOS app thats for all devices. I've designed it perfectly for the iPad but now I'm struggling a bit on resizing elements for smaller screens. My datagrids scale and move perfectly but when it comes to buttons, they just get warped and messed up. The down states on the buttons are massive and stretched and different to the up states. My logic tells me that if I scale the button, it should scale the up and down states accordingly as if you were just resizing on the stage. I'm just trying to make the buttons slightly bigger and move them over a bit..
if (Capabilities.screenResolutionX < 700) {
dg.move(120, 150);
dg.width = 1120;
dgPlace.move(70, 20);
dgPlace.width = 260;
dgPlace.height = 650;
dgPlace.rowCount = 21;
dgPlace.setRendererStyle("textFormat", myTextFormat3);
dgPlace.setStyle("headerTextFormat", myTextFormat3);
btnPlacesEditAdd.width = btnPlacesEditAdd.width+20;
btnPlacesEditAdd.height = btnPlacesEditAdd.height+20;
btnPlacesEditRemove.width = btnPlacesEditAdd.width+20;
btnPlacesEditRemove.height = btnPlacesEditAdd.height+20;
btnPlacesEditSet.width = btnPlacesEditAdd.width+20;
btnPlacesEditSet.height = btnPlacesEditAdd.height+20;
btnPlacesEditAdd.x = btnPlacesEditAdd.x+20;
btnPlacesEditAdd.y = btnPlacesEditAdd.y+20;
btnPlacesEditSet.x = btnPlacesEditSet.x+20;
btnPlacesEditSet.y = btnPlacesEditSet.y+20;
btnPlacesEditRemove.x = btnPlacesEditRemove.x+20;
btnPlacesEditRemove.y = btnPlacesEditRemove.y+20;
}

resizing of images in corona sdk for ipad and iphone

is there any possibility in corona sdk that we write one code for paticular application and it can be run on both ipad and iphone, without changing the coordinates of objects and sizes of images for both devices seperately?
Can it be possible through display.contentHeight and display.contentWidth?
Mud was basically correct. By setting the content width/height, Corona SDK will draw and scale your app on the iPhone / iPad (+retina) screens automatically. The best way to think of it is to design your app on a 320x480 screen - and then provide images for that screen size. You then create a 2nd set of images for the larger screens. By using Corona's display.newImageRect() it will load your small images for iPhone, and then the larger resolutio images on the iPad / retina displays.
Take a look at this article: http://developer.anscamobile.com/forum/2012/03/12/understanding-letterbox-scalling
Your config.lua should look like this:
application = {
content = {
width = 320,
height = 480,
scale = "letterbox",
xAlign = "center",
yAlign = "center",
imageSuffix = {
["#2x"] = 2
["#4x"] = 4
},
},
}
When you call display.contentHeight and display.contentWidth, you are simply reading those values from the config.lua file. I tend to use some global variables if I need to do any specific positioning calculations. Define these in your main.lua:
screenWidth = display.contentWidth - (display.screenOriginX*2)
screenHeight = display.contentHeight - (display.screenOriginY*2)
screenTop = display.screenOriginY
screenRight = display.contentWidth - display.screenOriginX
screenBottom = display.contentHeight - display.screenOriginY
screenLeft = display.screenOriginX
screenCenterX = display.contentWidth/2
screenCenterY = display.contentHeight/2
For example:
companyLogo = display.newImageRect("companyLogo.png",64,64)
You will need 1 64x64px image named companyLogo.png. This will be for < iPhone 4. You then need a 128x128px image named companyLogo#2x.png. Corona will use this automatically on the iPhone 4 and iPad. Again, another image that's 256x56 named companyLogo#4x.png will be used on the iPad 3 retina display.
Yes, it's possible. For example, if your app is written for 640x480, you can have it automatically scale to other resolutions by telling it how you want it scaled in your config.lua file:
application =
{
content =
{
width = 640,
height = 480,
scale = "letterbox"
},
}
More info.

Resources