How to dynamically load images in a layer using actionscript - image

I used the below code to load images that are present in my library:
Create_Image_With_Description();
function Create_Image_With_Description():Void {
this.createEmptyMovieClip("imageHolder", 600);
// Put Here Images URoL
imageHolder.loadMovie("Symbol 1");
// Position
imageHolder._x = 0;
imageHolder._y = 0;
// Size
imageHolder._xscale = 210;
imageHolder._yscale = 215;
// Example: my_mc.createTextField(instanceName:String, depth:Number, x:Number,
y:Number,width:Number, height:Number) : Void
this.createTextField("description1Field",1,10,203,120,20);
// Put Here Images description
description1Field.text = "Resident Evil: Afterlife";
}
Here symbol 1 is the image that i've converted into a symbol. When i tried running this i got an error saying "Error opening URL 'file:///E|/Symbol 1'".
I've also tried giving imageHolder.loadMovie("img1.jpg"); But still it didn't worked. Can anyone help me with this

Try replacing these lines:
this.createEmptyMovieClip("imageHolder", 1000);
// Put Here Images URL
this.attachMovie("img1", "img1", {_x:100, _y:100});

Related

Images not showing in update function using BackPack for Laravel

I´m saving images in my crud. The url is being stored in the DB correctly, however the image is not appearing when I try to edit the element. The image shows like this:
I'm using this mutator:
public function setImageAttribute($value)
{
$evidencia = "image";
$disk = "public";
$destination_path = "public/uploads/evidenciaQuejas";
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$evidencia});
// set null in the database column
$this->attributes[$evidencia] = null;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 1. Generate a filename.
$filename = md5($value.time()).'.jpg';
// 2. Store the image on disk.
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// 3. Save the path to the database
$this->attributes[$evidencia] = $destination_path.'/'.$filename;
}
}
Also, the folder that I created in the server to store the images ("public/uploads/evidenciaQuejas") says it has 0 archives inside even though the image is being stored without errors.
Could you help me please?

Setting link URL with Google Docs API doesn't result in update of image

I'm trying to update a placeholder image with a new image that has an updated URL. The URL in fact is a valid Google Static Map URL that I'm using in other contexts successfully. I'm using the Google Document API to manipulate the document. Following the code I've been using:
var element = body.findElement(DocumentApp.ElementType.INLINE_IMAGE).getElement();
var imageMap = element.asInlineImage();
// if there was an image found in document
if (imageMap != null) {
// get current parent and index inside parent
var parent = imageMap.getParent();
var childIndex = parent.getChildIndex(imageMap);
// remove image from paragraph
imageMap = imageMap.removeFromParent();
// get static image url for territory
var url = getStaticMapURLForTerritory(id);
Logger.log(url);
imageMap.setLinkUrl(url);
// create a new image
parent.insertInlineImage(childIndex, imageMap)
}
This seems to work fine in that it does update the image url correctly. However, the image itself (the result of the url) is not updated. When I click on the link URL it does return the correct image.
Is there a way to force a refetch of the image blob associated with the URL? I've also attempted to use UrlFetchApp but that complains about a missing size parameter (google static api) which is certainly included in the url string and within the max 640x640 bounds.
I've exhausted all my options unless....
TIA, --Paul
setLinkUrl only does that: sets the link. To actually add a new image you'll have to get its blob:
function replaceImage() {
// [...]
// get static image url for territory
const url = getStaticMapURLForTerritory(id)
const response = UrlFetchApp.fetch(url)
// create a new image
parent.insertInlineImage(childIndex, response.getBlob())
.setAltDescription(img.getAltDescription())
.setAltTitle(img.getAltTitle())
.setWidth(img.getWidth())
.setHeight(img.getHeight())
.setLinkUrl(url)
}
References
Class InlineImage (Google Apps Script reference)

Insert Image into a Google Sheet with Apps Script using base64 encoded data

Given some base64 encoded data for a png file, as in the example below from the image tag.
<img src="data:image/png;base64,R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7">
I need to create an image blob from the base64 encoded data for the insertImage() method.
sheetClass.insertImage(imageBlob, column, row)
Documentation:
Sheets Class - insertImage method
I've tried using the code below, but it throws the error:
Execution failed: Error retrieving image from URL or bad URL
The documentation states that the method needs a blob, not a URL, but it seems like it's expecting a link to an image file.
function insertImageFromBase64Src() {
var data = 'R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7';
var imageBlob = Utilities.newBlob(Utilities.base64Decode(data), 'image/png').getBytes();
var ss = SpreadsheetApp.getActiveSpreadsheet();//This code is bound to a Sheet
var po = {
shName:'Update File',
column:1,
row:37
}
var sh = ss.getSheetByName(po.shName);
var image = sh.insertImage(imageBlob, po.column, po.row);//Insert an image and return the image
}
How about this modification?
Modification points:
insertImage can use the blob and URL which is the direct link of the image file.
In your script, imageBlob is an byte array which is "number[]". By this, I think that an error occurs.
Please add the name to the blob.
When the name is not given, an error occurs.
Modified script:
When your script is modified, it becomes as follows.
function insertImageFromBase64Src2() {
var data = 'R0lGODlhDAAMAKIFAF5LAP/zxAAAANyuAP/gaP///wAAAAAAACH5BAEAAAUALAAAAAAMAAwAAAMlWLPcGjDKFYi9lxKBOaGcF35DhWHamZUW0K4mAbiwWtuf0uxFAgA7';
var imageBlob = Utilities.newBlob(Utilities.base64Decode(data), 'image/png', 'sample'); // Modified
var ss = SpreadsheetApp.getActiveSpreadsheet(); //This code is bound to a Sheet
var po = {
shName:'Update File',
column:1,
row:37
}
var sh = ss.getSheetByName(po.shName);
var image = sh.insertImage(imageBlob, po.column, po.row);//Insert an image and return the image
}
In this modification, it supposes that data can be correctly decoded.
References:
insertImage(blobSource, column, row)
insertImage(url, column, row)
If this was not the direct solution of your issue, I apologize.

ABCPdf - Image not a suitable format

In the end, my goal is to send a raw image data from the front-end, then split that image into however many pages, and lastly send that pdf back to the front-end for download.
But every time I use the theDoc.addImageFile(), it tells me that the "Image is not in a suitable format". I'm using this as reference: https://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/1-methods/addimagefile.htm
To troubleshoot, I thought that the image might not be rendering correctly, so I added a File.WriteAllBytes to view the rendered image and it was exactly what I wanted, but still not adding to the PDF. I also tried sending the actual path of a previously rendered image thinking that the new image might not have been fully created yet, but it also gave me the same error. Lastly, I thought PNGs might be problematic and changed to JPG but it did not work.
Here is the code:
[HttpPost]
public IActionResult PrintToPDF(string imageString)
{
// Converts dataUri to bytes
var base64Data = Regex.Match(imageString, #"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
/* Ultimately will be removed, but used for debugging image */
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string imgName= "Test.jpg";
string filename = Path.Combine(path, imgName);
System.IO.File.WriteAllBytes(filename, binData);
/***********************************************************/
using (Doc theDoc = new Doc())
{
// Using explicit path
theDoc.AddImageFile(#"C:\Users\User\Documents\Test.jpg", 1);
// Using variable
//theDoc.AddImageFile(filename, 1);
// What I really want
//theDoc.AddImageFile(binData , 1);
theDoc.Page = theDoc.AddPage();
theDoc.AddText("Thanks");
Response.Headers.Clear();
Response.Headers.Add("content-disposition", "attachment; filename=test.pdf");
return new FileStreamResult(theDoc.GetStream(), "application/pdf");
}
}
Try something like this (not tested, but cleaned up from my own code):
public int AddImageFile(Doc doc, byte[] data, int insertBeforePageID)
{
int pageid;
using (var img = new XImage())
{
img.SetData(data);
doc.Page = doc.AddPage(insertBeforePageID);
pageid = doc.Page;
doc.AddImage(img);
img.Clear();
}
return pageid;
}
To add a JPEG from a byte array you need Doc.AddImageData instead of Doc.AddImageFile. Note that AddImageFile / AddImageData do not support PNG - for that you would definitely need to use an XImage. The XImage.SetData documentation has the currently supported image formats.

Actionscript 3. Display alternative images (using conditionals) when mp3 available or not-available to play

I wondering the best way to handle this
I'm successfully loading sounds (audioMP3) from an XML file and handling the IO errors with EventListener.
I would like to have an image show on stage, when an MP3 is available or an alternative image when there is no MP3.
I've been trying to access the IO error and use it in conditionals to select the image e.g.
If there is an IO error then display btnAudioNo
Else display btnAudioYes
Here's the eventListemer:
audioMP3.addEventListener(IOErrorEvent.IO_ERROR, onSoundIOError, false, 0, true);
function onSoundIOError (e:IOErrorEvent){
trace(e.text);
removeEventListener(IOErrorEvent.IO_ERROR, onSoundIOError)
}
And my dodgy conditional attempt:
var btnAudioYes:Bitmap = new Bitmap(new(getDefinitionByName("btnAudioYes")) (0,0) );
var btnAudioNo:Bitmap = new Bitmap(new(getDefinitionByName("btnAudioNo")) (0,0) );
if(ioError = false){
addChild(btnAudioYes);
}
else {
addChild(btnAudioNo);
}
My questions are, how can I get this to work and is there a better way to determine if there is an MP3 file available (in the XML file) and display the appropriate image?
Many thanks for your suggestions.
Listener (in addition to the IOErrorEvent) to the ProgressEvent, if you get progress then the file exists and you can cancel (close) the loader. Unless you want the entire audio file loaded at this point, then listen for the complete event instead.
loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onSoundProgress, false, 0, true);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSoundLoadComplete); //use this only if you want to load the entire audio file at this point
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onSoundIOError, false, 0, true);
loader.load("your file");
function onSoundIOError (e:IOErrorEvent){
//this function will only run if the file does not exist
loader = null;
var btnAudioNo:Bitmap = new Bitmap(new(getDefinitionByName("btnAudioNo")) (0, 0) );
addChild(btnAudioNo);
}
function onSoundProgress(e:ProgressEvent) {
//this function will only run if the file DOES exist
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onSoundProgress); //we don't want this firing again
var btnAudioYes:Bitmap = new Bitmap(new(getDefinitionByName("btnAudioYes")) (0,0) );
addChild(btnAudioYes);
//if you you don't want to actually load the audio file, do this to cancel the load
loader.close(); //close the loader to keep from loading the rest of the file
loader.contentLoaderInfo.unloadAndStop(true);
loader = null;
}
//use this only if you want to load the entire audio file at this point
function onSoundComplete(e:Event):void {
//do whatever you need to do with the sound...
}

Resources