image-size(path)
Returns the width and height of the image found at path. Lookups are performed in the same manner as #import, altered by the paths setting.
Example:
width(img)
return image-size(img)[0]
height(img)
return image-size(img)[1]
image-size('tux.png')
// => 405px 250px
How to get the height and insert it into the css property?
For example:
.qwert
width image-width(test.jpg)
.qwert
width image-size('test.jpg')[0]
Related
How do I know when I should be appending "Bold" to the name of the font vs setting the font weight?
I have the following test function to demonstrate the issue:
public static bool IsBoldFont(string fontName, System.Windows.FontWeight fontWeight)
{
var typeface = new System.Windows.Media.Typeface(new System.Windows.Media.FontFamily(fontName), System.Windows.FontStyles.Normal, fontWeight, System.Windows.FontStretches.Normal);
typeface.TryGetGlyphTypeface(out System.Windows.Media.GlyphTypeface glyphTypeface);
return glyphTypeface.Weight == System.Windows.FontWeights.Bold;
}
And these are the results:
IsBoldFont("Arial Narrow", System.Windows.FontWeights.Bold); // false
IsBoldFont("Arial Narrow Bold", System.Windows.FontWeights.Regular); // true
IsBoldFont("Arial", System.Windows.FontWeights.Bold); // true
-- Update --
I think I simplified my question a bit too much. I am converting from one software package to another. The font specified is "Arial Narrow" and Bold weight (like in MS Word - select the font, then apply the Bold Weight to it, the Font "Arial Narrow Bold" does not exist in the list of fonts).
When converting the text to draw on the canvas, the font is not drawing Bold when I am asking for ("Arial Narrow", System.Windows.FontWeights.Bold), however it is correct when changing the font family name to ("Arial Narrow Bold", System.Windows.FontWeights.Regular). How am I supposed to know to append " Bold" to the end of the family name?
I have an Android project that uses several containers inside a Grid Layout.
The containers' height and width are different and I am looking for a way to make them square.
I have tried it the following way:
int w = container.getWidth();
container.setHeight (w);
This does not not work, because:
a) container.setHeight(i) does not change the height of the container, and
b) container.getWidth() returns 0.
What would be the best approach to obtain square containers?
EDIT
Here is a updated screenshot: left is before, right is after using the code sample.
Size is set by the layout manager. The layout manager effectively invokes setWidth/Height/X/Y to determine the bounds of the components. So any change you make to any one of those methods will be overridden by the layout manager.
To explicitly define the size override calcPreferredSize() and return a uniform size ideally one that is calculated and not hardcoded e.g.:
Container myContainer = new Container(new GridLayout(1, 1)) {
#Override
protected Dimension calcPreferredSize() {
Dimension d = super.calcPreferredSize();
int size = Math.max(d.getWidth(), d.getHeight());
d.setWidth(size);
d.setHeight(size);
return d;
}
};
I used the (new) GUI Builder and inserted an image (by way of adding a Label). However, it appears too big. Is there anyway I can scale and control the size? (I saw something which points to cloudinary but that seems too complicated. I just want to simply scale down the image.)
There are several ways to resize images in Codename One and I will mention few below:
1.
Use MultiImages in the GUI Builder. With this multiple sizes of images are generated from one image based on the sizes you specified. In your GUI Builder, Click Images -> Add Multi Images -> Select your image -> Check Preserve Aspect Ratio -> Increase the % that represents the percentage of the screen width you want the image to occupy. Set any DPI you don't require to 0.
2.
Use ScaledImageLabel or ScaledImageButton, it will resize the image the fill available space the component is occupying.
3.
Scale the image itself in code (This is not efficient, though):
public static Image getImageFromTheme(String name) {
try {
Resources resFile = Resources.openLayered("/theme");
Image image = resFile.getImage(name);
return image;
} catch (IOException ioe) {
//Log.p("Image " + name + " not found: " + ioe);
}
return null;
}
Image resizedImage = getImageFromTheme("myImage").scaledWidth(Math.round(Display.getInstance().getDisplayWidth() / 10)); //change value as necessary
4.
Mutate the image (Create an image from another image).
I am loading a grid dynamically in extjs. As you can see below the column "Created" is not wide enough to display whole text in it. I want to set every column's width such that it display's its text completely.
Is this possible to do? Any suggestion?
Thanks for help.
use parameter width: ... with your column config. As simple as this. I do not see your code so I am guessing.
However it look like you have more vertical space -> maybe break date in 2 lines (using template) would be solution, or you can have special css class just for this cell with smaller letter in order to fit.
Edit:
in your case it could be combination of defaultWith in ColumnModel (at least get 120 to fit your date, if more columns grid would adjust) and setColumnWith() dynamically based on length of data and number of columns - logic is up to you
Thanks bensiu, I implemented the login. However, I cannot say that this is the ideal solution but it solves my purpose.
First, i navigate through data and find the longest string in that column (including header name of that column).
// Store the longest string for each column in columns[col].maxstring
// Define a hidden label
{
xtype: 'label',
id: 'lblTab',
hidden: true
}
var lblTab = Ext.getCmp('lblTab');
var hiddenField = Ext.util.TextMetrics.createInstance(Ext.getCmp('lblTab').el);
var widthValue = 0;
// Iterate through each columns to set its maximum width
for(var col in columns) {
// find width of string
widthValue = hiddenField.getWidth(columns[col].maxstring);
// set column width
colModel.setColumnWidth(columns[col].index, widthValue + 20, false);
}
I hope this helps somebody.
I need to resize and crop to exactly 60x80px from various size and
aspect ratio. Just before i put into Datastore. Anyone already got
this issue resolved.
Currently i already succed to just transform it to exact height (80px)
with various width which nott look so good when i try to display it on
a list. e.g jcaroussel.
My db.put code is like bellow:
if users.get_current_user():
personal.personal_id = int(self.request.get('personal_id'))
personal.name = self.request.get('name')
personal.latitude = self.request.get('latitude')
personal.info = self.request.get('info')
photo = images.resize(self.request.get('img'), 0, 80)
personal.photo = db.Blob(photo)
personal.lc_id = int(self.request.get('lc_id'))
personal.put()
self.redirect('/admin/personal')
else:
self.response.out.write('I\'m sorry, you don\'t have permission to add this LP Personal Data.')
I just want to do similar result when we upload our avatar on google
talk/google chat.
Anyone solved this?
Thx
After your resize your image down to 80 pixels in height, you would have to use the crop function as defined here. For example:
img = images.Image(self.request.get('img'))
img.resize(0, 80)
resized_img = img.execute_transforms(output_encoding=images.JPEG)
left_x = (resized_img.width - 60) / 2
resized_img.crop(left_x, 0, left_x + 60, 80)
cropped_img = resized_image.execute_transforms(output_encoding=images.JPEG)
In my example it crops to the center of the image.
It assumes that the resized image is at least 60 pixels wide, but obviously you would have to add some checks to confirm this, because a user might not upload an image in the right size.
I used something else:
Resize the original image to your max height (80)
Store the resized (but complete/not cropped) image
Display it inside a <div> that has the following CSS: width: 60px; height: 80px; overflow: hidden;
That way it will show nicely in your list, but you can still display the complete resized picture on your user's profile page (looking at you code I imagine that's what you are trying to do, right?)