Is there a JavaScript alternative to PIL? - javascript

I'm trying to convert some old python code to JS and I'm having trouble finding an alternative to it. These are some examples of the python code I'm trying to convert.
image_array = np.ones([16, 16, 4],np.uint8)*255
im = Image.fromarray(image_array)
im.save(name)
----------------------------
image = Image.open(new_image_filename)
impt = np.array(image)
Sorry if this doesnt make sense - thanks for taking the time to look at it

Related

how can i create a reg exp or array to change this?

ok guys i have been working on these, this is like my main project and im pretty anxious about it, i have been practicing but im still a newbie. My code is like this and it does what it has to do, but im thinking that it could be improved to be better and more reusable, sorry to spam if i am, i already asked on the spanish version of the website with no satisfactory answer, im new to web developing and to this site, i always read the content on this site to answer my questions but for this time i didnt know how to exactly use the previous answers to fix my code, since im new to web developing and im trying to use jquery bit by bit. As i said my question is how can i create an array or a reg exp that does all the things this code does? without having to use .replace function all those times
i have tried urlencode function, and tried to iterate over arrays on jquery but i still dont know how to do it properly.
$( ".linkbestia" ).each(function() {
lnk = $(this).text();
enlace= $(this).attr("href");
espacios=lnk.replace(" ","_");
maslimpio=espacios.replace("'","%27");
muchomaslimpio=maslimpio.replace("(","%28");
muchomuchomaslimpio=maslimpio.replace(")","%29");
nuevoenlace=$(this).attr("href",enlace+muchomuchomaslimpio);
});
the actual output is for example codedquote'replaced space as i said it already does what it has to do, but i know it can be improved, i hope you guys help me since in my country these kind of questions cant be answered without a ton of difficulties
what it does right now:
what the user writes would look like this
the result would look like this
If I understand correctly you want to take href from below:
<a class="linknpc" href="url/in/url/url/The%27White_Mob">
and expected output is
The'White_Mob
after you get the href and lets say the var enlace looks like below.
var enlace = "url/in/url/url/The%27White_Mob"
Below will first use String split on '/' to get all sections from href and from resultant array get the last element by pop() and use decodeURIComponent to decode the encoded uri.
var ans = decodeURIComponent(enlace.split('/').pop())
ans would now have the value: The'White_Mob
note: If the href ends with '/' then you need to adjust above solution accordingly

JS variable inside of PHP inside of JS inside of PHP [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 4 years ago.
Having a bad day. This one has stumped me all morning. All the solutions I've found have stopped one step short of where I need to go.
I have a legacy PHP/JS app that I'm working on. Rather than trying to explain it, I'll just show what I need to do.
<?php
$phpDate_1 = new Date($someDate);
$phpDate_2 = new Date($someOtherDate);
//...There are a bunch of these
$phpDate_n = new Date($endOfTime);
<script language="javascript">
function myFunction() {
var line = aUserSelection; //an int from user which tells me what date to use
//Next line is the problem. I'm trying to pull the month from the appropriate PHP date into the JS variable.
var theMonth = "<?php echo $phpDate_" + line + "->getMonth();?>";
}
</script>
?>
I must have tried 20-30 combinations of single and double quotes, escapes, dots, pluses, and so on, but I keep getting errors over the "line" part. Unexpected character, encapsed strings, etc.
Hoping someone can point me in the right direction because my brain is fried at this point. Answers in pure JS and PHP only please because that's how the app is built. Thanks.
You need to close your php (?>) before outputting the javascript to fix the syntax error that you got.
However, with that said, you are trying to incorporate the javascript line variable into the variable name for $phpDate, to generate something like $phpDate_1.
If you don't want to go with an AJAX solution, your best bet would be to output each line's date into a javascript array. This is strongly discouraged, but if this is a legacy application that you cannot make many changes to, this might be your only option.

Bokeh: App Not Visualizing--Requirements? (extra_generated_classes, jsmodel)

I'm new to Bokeh, and am trying to create a web-app. I'm having issues where when I run the server, and navigate to the specified web URL, nothing shows beyond a small "link to this" in the upper left hand corner. For reference, I'm using python 2.7, via Anaconda, on Windows7.
I first created a simple example, modeled off of the stock applet. I noticed that in the class Dashboard(VBox), there were, in addition, declarations of extra_generated_classes, and jsmodel. When I omitted these two lines, nothing would show.
I read through some of the bokeh code, but I'm still not quite understanding what the two lines do, and how to set them properly. In my new example, my formatting looks like this
self.children = [self.filterrow, self.lineplot1]
self.filterrow.children = [self.filter_box, self.input_box]
self.filter_box.children = [self.ticker_select, self.date_select]
self.input_box.children = [self.value_select, self.value1_select]
where
lineplot1 = Instance(Plot)
filterrow = Instance(HBox)
ticker_select = Instance(Select)
date_select = Instance(Select)
value = String(default = '')
value1 = String(default = '')
and in my def create(cls)
obj = cls()
obj.filterrow = HBox()
obj.filter_box = VBoxForm()
obj.input_box = VBoxForm()
I've compared my working applet side by side with my non-showing applet, and can't find any significant format differences. Learning by replications, I have
class Dashboard(VBox):
extra_generated_classes = [["Dashboard", "Dashboard", "VBox"]]
jsmodel = "VBox"
in the non-functioning code. Is this correct? How should these two lines be set? Do I need both? Am I missing something? After repeated examination and comparison of the code, I still don't understand why one visualizes properly and the other doesn't.
If this isn't the issue, what is the best way for me to debug the visualization portion of the applet? Any assistance would be greatly appreciated. Thanks!

Javascript to jquery issue

I made a pure JavaScript file the past days. It's a fully operational BlackJack game. However i was told to try and use as much jquery as possible on my existing file. So I can understand the basics of jQuery.
Things like
$("#Result").empty();
and
$("#hit").attr("disabled", "disabled");
$("#hit").removeAttr("disabled");
all work fine. But i have a problem with this one for example:
function player_blackjack() {
$("#Result").text("BlackJack!");
var bet = parseInt($("#bet").val());
var bank = parseInt(document.getElementById("Bank").innerHTML);
bank = bank + (bet * 2.5);
document.getElementById("Bank").innerHTML = bank;
start_game_buttons();
}
The first lines work, all except the var bank and the line above start_game_buttons();, thats why they are still javascript written.
If i change the var bank line to this one:
var bank = parseInt($("#Bank").html);
It just doesn't work. When i run this and make myself get a blackjack ill get a NaN where the bank should be. I also tried:
var bank = parseInt($("#Bank").val());
Im basically just trying whatever i can find, but since i can't figure it out im trying my luck here.
Thanks in advance!
You forgot the () after the html method, it should be:
var bank = parseInt($("#Bank").html());
Although, why are you using parseInt on an html() call? If this is an input -- use .val()

Converting JavaScript clicking to Selenium

Apparently the task I asked about earlier (JavaScript Automated Clicking) is impossible in JavaScript, or at the very least extremely difficult.
However, I have found the documentation on Selenium and how to use it extremely uninviting and difficult to understand.
Perhaps someone could help me translate this code to Selenium or, alternatively, help me with particular elements I'm having difficulty with.
function pausecomp(ms) {
ms = ms + new Date().getTime();
while (new Date() < ms){}
}
var itemlist, totalnumber, i;
itemlist = document.getElementsByClassName("image");
totalnumber = parseInt(document.getElementById("quickNavImage").childNodes[3].firstChild.firstChild.nodeValue.replace(/[0-9]* of /, ""));
for(i = 0; i < totalnumber; i = i + 1) {
console.log(i);
itemlist[i].childNodes[1].click();
pausecomp(3000);
}
Now, I know I can get elements by Class Name in Selenium, but how do I get specific child nodes?
Likewise, how do I use regex to cut out the total number of items that needs to be clicked? It is only available in text form.
And finally, how do I iterate in Selenium?
Please note, I have no available programming environments on these computers. So I cannot use Python, C#, etc. hooks unless they can be directly imported into the Selenium IDE itself. However, the documentation is difficult for me to understand, so I don't believe that is possible.
I figured it out. Please take a look at my previous linked post. I was being an idiot. I'll put the answer up there.

Categories