MultiDPIBitmapSource in BitmapFill doesn't work - flash-builder

MultiDPIBitmapSource in BitmapFill doesn't work.
Here is my code:
`
<s:Rect id="background2" left="0" right="0" top="0" bottom="0" percentWidth="100" percentHeight="100" radiusX="20" >
<s:fill >
<s:BitmapFill id="bgFill" fillMode="repeat">
<s:source>
<s:MultiDPIBitmapSource source160dpi="#Embed('images/backgroundSki/240/abiSefid.jpg')"
source240dpi="#Embed('images/backgroundSkin/240/abiSefid.jpg')"
source320dpi="#Embed('images/backgroundSkin/320/abiSefid.jpg')" />
</s:source>
</s:BitmapFill>
</s:fill>
</s:Rect>`

work with flash builder some times become so much complicated than another sdk's like visual stadio... we should take care about detail for example in MultiDPIBitmapSource help of flash builder say's:
This class provides a list of bitmaps for various runtime densities.
It is supplied as the source to BitmapImage or Image and as the icon
of a Button
. The components will use the Application.runtimeDPI to choose which image to display.
so we cant use MultiDPIBitmapSource in bitmapFill in rect . also we maybe want use this code for solve problem:
<fx:Script>
<![CDATA[
.
.
switch( FlexGlobals.topLevelApplication.runtimeDPI)
{
case DPIClassification.DPI_240 :
bgFill.source = "images/backgroundSkin/160/image.jpg
break;
case DPIClassification.DPI_160 :
bgFill.source = "images/backgroundSkin/160/image.jpg
break;
case DPIClassification.DPI_320 :
bgFill.source = "images/backgroundSkin/160/image.jpg
break;
}
.
.
]]>
</fx:Script>
.
.
<s:Rect id="background2" left="0" right="0" top="0" bottom="0" width="100%" height="100%" >
<s:fill>
<s:BitmapFill id="bgFill" fillMode="repeat" />
</s:fill>
</s:Rect>
but you can see this code also dont work i think the id of BitmapFill is anknown in script code .. any way the only way that worked for me was using of loader :
.
.
.switch( FlexGlobals.topLevelApplication.runtimeDPI)
{
case DPIClassification.DPI_240 :
loader.load(new URLRequest("images/backgroundSkin/240/image.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
break;
case DPIClassification.DPI_160 :
loader.load(new URLRequest("images/backgroundSkin/160/image.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
break;
case DPIClassification.DPI_320 :
loader.load(new URLRequest("images/backgroundSkin/320/image.jpg"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
break;
}
}
public function loaderCompleteHandler(evt:Event):void
{
bgFill.source = evt.target.content;
}

Related

How to make animate drawing a border? (Vanilla JS solution needed)

I am trying to build a relaxation app.
For this I need to get a animation of border being drawn.
The way I tried is not giving a smooth transition.
How to achieve the same?
A part of javascript code and codepen link is shared below
https://codepen.io/TM06/pen/RwrRxLQ
JS
if(count && seconds<=4){
document.getElementById("message").innerText = "Breathe In";
switch(seconds){
case 1 :
document.getElementById("container").style.borderTop = "8px solid red";
break;
case 2 :
document.getElementById("container").style.borderRight = "8px solid red";
break;
case 3 :
document.getElementById("container").style.borderBottom = "8px solid red";
break;
case 4 :
document.getElementById("container").style.borderLeft = "8px solid red";
break;
}
}else if(count === false && seconds< 5){
document.getElementById("message").innerText = "Breathe Out";
switch(seconds){
case 1 :
document.getElementById("container").style.borderLeft = "0px";
break;
case 2 :
document.getElementById("container").style.borderBottom = "0px";
break;
case 3 :
document.getElementById("container").style.borderRight = "0px";
break;
case 4 :
document.getElementById("container").style.borderTop = "0px";
break;
}
}
I have acheived the border animation. Sharing the codepen link here:
https://codepen.io/TM06/pen/wvMgeaw
<div class="container h-100 align-items-center" id="container">
<div class="topBar" id="topBar"></div>
<div class="rightBar" id="rightBar"></div>
<div class="bottomBar" id="bottomBar"></div>
<div class="meter9"><span class="leftBar" id="leftBar"></span></div>
This is not yet perfect though.

How can I enhance the quality of images generated from PDF?

We use TYPO3 9.5.13, GraphicsMagick 1.3.29, Ghostscript 9.27, BK2K\\BootstrapPackage 11.0.1
Using PDFs as normal images is no problem.
But now I want a 'preview' of the PDFs in full column width (~1000px). And although the PDF has a high resolution, the generated Image has a width of 595px only and any text is nearly unreadable.
The problem occurs with Image-CEs like in the uploads CE, which I want to enhance:
each time I want the image using the full column width it renders in a bad resolution and the image seems distorted.
here a small area from the generated image:
and the same area from the PDF as shown in PDF-reader:
The fluid part:
<img loading="lazy"
src="{f:uri.image(image: file, cropVariant: 'default', maxWidth: 1100)}"
width="{bk2k:lastImageInfo(property: 'width')}"
height="{bk2k:lastImageInfo(property: 'height')}"
intrinsicsize="{bk2k:lastImageInfo(property: 'width')}x{bk2k:lastImageInfo(property: 'height')}"
title="{file.properties.title}"
alt="{file.properties.alternative}">
which results in something like:
<img loading="lazy"
src="/fileadmin/_processed_/3/2/csm_Warum_D-Arzt_6afd8ad8d4.png"
intrinsicsize="595x842"
title=""
alt=""
width="595"
height="842">
Edit:
In case of using this FLUID:
<img loading="lazy"
src="{f:uri.image(image: file, cropVariant: 'default', width: 1100)}"
width="{bk2k:lastImageInfo(property: 'width')}"
height="{bk2k:lastImageInfo(property: 'height')}"
intrinsicsize="{bk2k:lastImageInfo(property: 'width')}x{bk2k:lastImageInfo(property: 'height')}"
title="{file.properties.title}"
alt="{file.properties.alternative}">
I get:
<img loading="lazy"
src="/fileadmin/_processed_/3/2/csm_Warum_D-Arzt_2ffb63b15f.png"
intrinsicsize="1100x1557"
title=""
alt=""
width="1100"
height="1557">
the image is bigger (and overflow the container) but the quality is worse the same, notice the bigger pixels:
Actually, a PDF is NOT an image. It is a container format which can contain vectors and images with different colorspaces and dimensions. A bitmap image has fixed dimensions width, height, density, a PDF not. Originally, it was created and optimized to work for printers, not for screens.
TYPO3 reflects that with a message in the backend:
IMHO, there is no perfect way of handling PDFs to behave like images, as you know the output format, but not the input format (properly). Two ways to get acceptable results:
Extend content elements or create new ones and add a second image slot for PDF preview images. Create the preview images yourself with a graphical program.
Write your own viewhelper and create your own thumbnails
Solution 1 will lead to more work for editors. Would be no best practise for me.
I would go with an own viewhelper.
Add your own render type for PDFs:
<f:switch expression="{file.type}">
<f:case value="5">
<f:render partial="Media/Type/Pdf" arguments="{file: file, dimensions: dimensions, data: data, settings: settings}" />
</f:case>
<f:defaultCase>
<f:render partial="Media/Type/Image" arguments="{file: file, dimensions: dimensions, data: data, settings: settings}" />
</f:defaultCase>
</f:switch>
Partial Media/Type/Pdf
{namespace cv=Conversion\HelperUtils\ViewHelpers}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:ce="http://typo3.org/ns/TYPO3/CMS/FluidStyledContent/ViewHelpers" data-namespace-typo3-fluid="true">
<cv:forEachPdfThumbnail document="{file}" pages="1" as="pdfPreviewPage">
<f:image src="{pdfPreviewPage}" alt="" />
</cv:forEachPdfThumbnail>
</html>
ViewHelper:
This viewhelper convert multiple pages from a PDF, using the CommandUtility::imageMagickCommand. You can raise the density to a higher value to improve quality.
As mentioned, this viewhelper was developed a few years ago and could be improved (e.g. saving to fileadmin/processed instead of typo3temp. Feel free to clone and improve: https://github.com/conversion1/t3-pdfthumbnailviewhelper/blob/master/ForEachPdfThumbnailViewHelper.php
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$templateVariableContainer = $renderingContext->getVariableProvider();
/** #var \TYPO3\CMS\Core\Resource\FileReference $document */
$document = $arguments['document'];
$pages = explode(',', str_replace(' ', '', $arguments['pages']));
$colorspace = TRUE === isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace']) ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'] : 'RGB';
$absFilePath = GeneralUtility::getFileAbsFileName($document->getOriginalFile()->getPublicUrl());
$destinationPath = 'typo3temp/';
$destinationFilePrefix = 'pdf-prev_' . $document->getOriginalFile()->getNameWithoutExtension();
$destinationFileExtension = 'png';
$output = '';
foreach ($pages as $pageNumber) {
if($pageNumber > 0) {
$pageNumber = intval($pageNumber);
} else {
$pageNumber = 1;
}
$destinationFileSuffix = '_page-' . $pageNumber;
$absDestinationFilePath = GeneralUtility::getFileAbsFileName($destinationPath . $destinationFilePrefix . $destinationFileSuffix . '.' . $destinationFileExtension);
$imgArguments = '-colorspace ' . $colorspace;
$imgArguments .= ' -density 300';
$imgArguments .= ' -sharpen 0x.6';
$imgArguments .= ' "' . $absFilePath . '"';
$imgArguments .= '['. intval($pageNumber - 1) .']';
$imgArguments .= ' "' . $absDestinationFilePath . '"';
if(!file_exists($absDestinationFilePath)) {
$command = CommandUtility::imageMagickCommand('convert', $imgArguments);
CommandUtility::exec($command);
}
$thumbnail = substr($absDestinationFilePath, strlen(Environment::getPublicPath()));
$templateVariableContainer->add($arguments['as'], $thumbnail);
$output .= $renderChildrenClosure();
$templateVariableContainer->remove($arguments['as']);
}
return $output;
}
Edit:
A third way: You can use a JavaScript library to generate thumbnails on the fly. E.g. https://github.com/mozilla/pdf.js

PHP InstanceOf works locally but not on host server

I have an issue with PHP 7's instanceof statement that is only happening on certain conditions.
It seems that instanceof works locally on my dev machine (MAMP Pro running PHP 7.0.13) but not on my Hosted Server (HostEurope, PHP 7).
I have tried the following :
downgrading to PHP 5.6
using is_a instead
Using fully qualified name e.g. \Site\Ad
but they all exhibit the same behaviour.
I've tried Googling "PHP instanceof not working" and variations of it but I haven't found anything relevant.
I was wondering if anyone had experienced something similar or possible solutions to try?
The Code in question is:
<?php
namespace Site;
require_once(__DIR__."/../interface/IOutput.php");
require_once(__DIR__."/../lib/Lib.php");
require_once(__DIR__."/../site/AdMediumRectangle.php");
require_once(__DIR__."/../site/AdSnapBanner.php");
require_once(__DIR__."/../const/Const.php");
class AdFactory
{
/**
* Define(AD_BANNER, 0);
* Define(AD_RECTANGE, 1);
* Define(AD_SUPERBANNER, 2);
* Define(AD_SKYSCRAPER, 3);
**/
/**
* #param $object
* #return AdMediumRectangle|AdSnapBanner|string
*/
public static function CreateObject($object)
{
$ad = wire(pages)->get("/ads/")->children->getRandom();
if ($ad == null)
return new \Exception("No Random Ad found");
switch ($object) {
case AD_BANNER:
echo "AD_Banner Selected\r\n";
$adSnapBanner = new AdSnapBanner($ad);
return $adSnapBanner;
break;
case AD_RECTANGLE:
echo "AD Rectangle Created\r\n";
$adRectangle = new AdMediumRectangle($ad);
return $adRectangle;
break;
case AD_SUPERBANNER:
case AD_SKYSCRAPER:
default:
echo "AdFactory BlankObject created";
return "";
break;
}
}
public static function Markup($object)
{
$obj = AdFactory::CreateObject($object);
if (($obj instanceof AdSnapBanner) || ($obj instanceof AdMediumRectangle)) {
echo "InstanceOf worked";
return $obj->Markup();
}
else {
echo "return blankString";
return "";
}
}
}
Update : This is the code that calls the above AdFactory class
<?php
namespace Site;
require_once(__DIR__."/../interface/IOutput.php");
require_once(__DIR__."/../lib/Lib.php");
require_once(__DIR__."/../factory/AdFactory.php");
require_once (__DIR__."/../const/Const.php");
class AdInjector
{
public static function Inject($page, $ad_pos)
{
//Select an Ad from /Ads/ according to criteria
//$ads = wire(pages)->get("/ads/")->children;
$count = 1; //$ads->count();
if ($count > 0) {
$mod = $page->id % 3;
echo "mod=" . $mod . "\r\n";
if ($mod == $ad_pos) {
switch ($mod) {
case AD_POS_TITLE;
case AD_POS_BANNER:
//Pick an Snap Banner
echo "Banner Injected (banner):" . AD_BANNER . "\r\n";
return AdFactory::Markup(AD_BANNER);
break;
case AD_POS_SIBLINGS:
echo "Banner Injected (rect):" . AD_RECTANGLE . "\r\n";
//Pick an Ad Rectangle
return AdFactory::Markup(AD_RECTANGLE);
break;
default:
return "";
break;
}
} else
return "";
} else
return "";
}
}
instanceof is a language construct which is so essential to PHP that it is de facto impossible not to work properly.
The code you provided is not enough to tell where the issue might be happening.
Chances are, you have a folder not readable on your online server and simply get somewhere a null value instead of an expected object along your code. Ask yourself: "If it is not the object I expect, what else is it?"
Use var_dump() or printf() to investigate what your variables actually contain and you will find the error soon.
For your code, PHPUnit tests would be a benefit, or at least the use of assert() here and there in your code.
Turns out there was a bug in 1 of the API calls I was making to the Processwire CMS.
$ad = wire(pages)->get("/ads/")->children->getRandom();
And my local and server instance of Processwire was not the same version, which was news to me. I normally have it synchronised, including any modules I use.
I also suspect my null check is not correct PHP, to add to the problem.
It has to do with namespaces used in the code:
Locally (Code with no namespaces) I used this, working fine:
if ($xmlornot instanceof SimpleXMLElement) { }
But on the server (code with namespaces) only this worked:
if ($xmlornot instanceof \SimpleXMLElement) { }
See also this question/answer: instanceof operator returns false for true condition

How to display dynamic checkboxes using dojo

I want to display dynamic checkboxes by iterating json array object. Can anyone guide me how can we do this?
After doing some internet surfing and playing around code I able write below code, which working fine for my scenario. So thought it will be helpful for others.
for ( var i = 0; i < roleJSON.length; i++) {
var role = roleJSON[i];
var tr = dojo.create("tr",{id:"rolebasecheckbox"+i,'class':'rolebasecheckbox'});
alert("tr=" + tr);
var td= dojo.create("td",{innerHTML:'<input id="roleBaseCb_'+i+'" value="'+role.role_id+'" dojoType="dijit.form.CheckBox" onclick="alert('onclick event')" type="checkbox" /> <label for="roleBaseCb_'+i+'">'+role.role_name+'</label>',align:'center'},tr);
alert("td=" + td);
if(i==0){
alert("i is 0");
dojo.place(tr, "roleBaseComboTR", "after");
}else{
dojo.place(tr, "rolebasecheckbox"+(i-1), "after");
}
}

Check from theme's .tpl file for enabled module?

How can I check in theme's .tpl file with "If" operator is there enabled module(s) in a certain hook?
{if !empty($hook_name)}
{$hook_name}
{/if}
I do not still find any reason to do this checking. But anyway, there is a solution.
Surround your code in template by:
{if $some_modules_enabled}
...
{/if}
And put the below code in a controller, ex: FrontController.php
$id_hook = Hook::get($name_of_the_hook);
$some_modules_enabled = false;
foreach ( Hook::getModulesFromHook($id_hook) as $row ) {
if ( Module::isEnabled( $row['name'] ) ) {
$some_modules_enabled = true;
break;
}
}
$this->context->smarty->assign('some_modules_enabled', $some_modules_enabled);