How to Dynamically Change size of Image in Sitecore? - sitecore

I created a web service and had imagefield from the sitecore6.6. Now i am want to change the width and height of image dynamically so that i have big image on the fly. There are almost 1000 pictures which require size change . Any help...

You can use several query string parameters in the url of the image to let Sitecore modify the image. The image has to be a Sitecore Media item.
Here is a list of the supported query string parameters:
w: Width in pixels
h: Height in pixels
mw: Maximum width in pixels
mh: Maximum height in pixels
la: Language (defaults to context language)
vs: Version (defaults to latest version)
db: Database name (defaults to context database)
bc: Background color (defaults to black)
as: Allow stretch (as=1)
sc: Scale by floating point number (sc=.25 = 25%)
thn: Thumbnail (thn=1)
dmc: Disable media caching, both retrieval and storage (dmc=1)
In your case you can use for example the ?as=1&w=600 to get the image resized to 600px width.
You can also do this programmatically to set the MediaUrlOptions when creating the mediaUrl:
var mediaOptions = new MediaUrlOptions {AllowStretch = true, Width = 600};
var mediaUrl = MediaManager.GetMediaUrl(mediaItem, mediaOptions);

Related

Image column of Sharepoint List not displaying in Gallery control in PowerApps

My sharepoint list has image column of type "Thumbnail" which I fetch in Gallery control in Powerapps but it does not show:
2 column Image1 (internal name Images), Image2 (internal name Image2)
In gallery set data source to SharePoint list
I used ThisItem.Image2 but does not display image col.
Tried with Filter('SPList', ID = ThisItem.ID).Image2 but failed gives error "Expected Image value."
I also set data source of Gallery control to the Image using
First('SharePointList').Images
and get Image using ThisItem.small
The image column is not displaying. Where is it wrong?

How to load large images in PowerBi

I want to load pictures in PowerBi, problem is that pictures are a bit bigger than 32kb so it's showing just a part of the picture.
Is there some quick way to go around PowerBi limitation and display entire picture?
I fetched pictures from activite directory, then I converted binary file to text in order to set them as a picture (using this formula : data:image/jpeg;base64)
There is a great article by Chriss Webb, Storing Large Images In Power BI Datasets, from which I will copy the essentials here, in case the original article is not available.
Quote from Chriss Webb's article
The maximum length of a text value that the Power Query engine can load into a single cell in a table in a dataset is 32766 characters – any more than that and the text will be silently truncated. To work around this, what you need to do is to split the text representation of the image up into multiple smaller text values stored across multiple rows, each of which is less than the 32766 character limit, and then reassemble them in a DAX measure after the data has been loaded.
Splitting the text up in M is actually not that hard, but it is hard to do efficiently. Here’s an example of an M query that reads all the data from all of the files in the folder above and returns a table:
let
//Get list of files in folder
Source = Folder.Files("C:\Users\Chris\Documents\PQ Pics"),
//Remove unnecessary columns
RemoveOtherColumns = Table.SelectColumns(Source,{"Content", "Name"}),
//Creates Splitter function
SplitTextFunction = Splitter.SplitTextByRepeatedLengths(30000),
//Converts table of files to list
ListInput = Table.ToRows(RemoveOtherColumns),
//Function to convert binary of photo to multiple
//text values
ConvertOneFile = (InputRow as list) =>
let
BinaryIn = InputRow{0},
FileName = InputRow{1},
BinaryText = Binary.ToText(BinaryIn, BinaryEncoding.Base64),
SplitUpText = SplitTextFunction(BinaryText),
AddFileName = List.Transform(SplitUpText, each {FileName,_})
in
AddFileName,
//Loops over all photos and calls the above function
ConvertAllFiles = List.Transform(ListInput, each ConvertOneFile(_)),
//Combines lists together
CombineLists = List.Combine(ConvertAllFiles),
//Converts results to table
ToTable = #table(type table[Name=text,Pic=text],CombineLists),
//Adds index column to output table
AddIndexColumn = Table.AddIndexColumn(ToTable, "Index", 0, 1)
in
AddIndexColumn
Here’s what the query above returns:
The Pic column contains the split text values, each of which are less than the 32766 character limit, so when this table is loaded into Power BI no truncation occurs. The index column is necessary because without it we won’t be able to recombine all the split values in the correct order.
The only thing left to do is to create a measure that uses the DAX ConcatenateX() function to concatenate all of the pieces of text back into a single value, like so:
Display Image =
IF(
HASONEVALUE('PQ Pics'[Name]),
"data:image/jpeg;base64, " &
CONCATENATEX(
'PQ Pics',
'PQ Pics'[Pic],
,
'PQ Pics'[Index],
ASC)
)
…set the data category of this measure to be “Image URL”:
…and then display the value of the image in a report:
Storing images directly in Power BI is not the best option as using the convert to base64 method you'll be limited to 32KB in size. If possible it would be best to extract the images, and place them in a Azure Blob Store (or other accessible store) and reference them from there. You can use the datatype Image URL to show in a table, or the HTML viewer custom visual to show the image via a url. You'll have to use Power BI to get the list of images in Blob Storage, but if the image name is the same you could link that table to your dataset.
This worked well except:
Image type is hard-coded
Version 2021-07 Desktop doesn't have ImageURL visualization.
Also Card, MultiCard and two free visualizations, Chiclet Browser and Image Grid, but none of these showed my PNG image. Perhaps because it is not JPEG? Image meta data should be correct.
So I managed to use show a miniature picture in a table.

Tabulator - responsive - Height of table

I really like tabulator but cant seem to get it to adjust to the height of the device. If I fix a height
e.g.
var table = new Tabulator("#example-table", {
height:"600px",
If obviously looks bigger on a mobile etc
Is there a way of making the table 90% or whatever of the window height ?
cheers
you can set the height as a percentage:
var table = new Tabulator("#example-table", { height:"100%",
The height property will take any valid CSS height value

Openpyxl: how change row height with write_only cells and workbook

I neeed to create xls file in write-only mode and customize rows height. But rows height stay by default if i use write_only=True.
row = []
book = Workbook(write_only=True)
sheet = book.create_sheet()
cell_1 = WriteOnlyCell(sheet)
# styling and filling cell data
row.append(cell_1)
cell_2 = WriteOnlyCell(sheet)
# styling and filling cell data
row.append(cell_2)
sheet.append(row)
sheet.row_dimensions[len(sheet.rows)].height = 30
Without write_only all works perfect.
Must be done before any cells are added. See the warning section at the bottom of openpyxl.readthedocs.io/en/latest/optimized.html
Row and Column Dimensions are not available in write-only mode.

How can I incorporate in a ribbon category, 2 panels with different image resources?

I am working with CMFCRibbonCategory and my category should have 2 panels. The problem is that I would like to specify a set of button images for each panel. I don't want to join the two bmp files into one in order to use them.
This is how I normally set the image for a button:
_btnTest = new CMFCRibbonButton(ID_BTN_TEST, CResourceHelper::GetStringFromRes(IDS_BTN_TEST), 1, 1);
_btnTest->SetAlwaysLargeImage(TRUE);
_ribbonPanel->Add(_btnTest);
The value 1 specifies which image I want to use. I previously set the image resource for the entire category where I am going to add my panel.
_ribbonCategory = wndRibbonBar->AddCategory(
CResourceHelper::GetStringFromRes(IDS_CATEGORY_NAME),
IDB_TOOLBAR_IMG,
IDB_TOOLBAR_IMG,
CSize(16, 16),
CSize(32, 32),
-1,
NULL);
Therefore, how can I set the 2 image resources?
I have my icons separated each one, and in my CMFCRibbonBar derived class, I use something like:
CMFCToolBarImages* pImageList;
pImageList= &GetCategory(0)->GetLargeImages();
pImageList->AddIcon(theApp.LoadIcon(IDI_SOME_ICON), true);
//.. and so on for every button and category assuming tha you have correctly set the image indexes