mercredi 1 avril 2015

Can some one please help me in correcting the mistake I'm making in HTML DOM parsing?

I've one sample string as follows :



$feed_status = Nice to see you all back again <img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /><img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" /><img src=\"http://ift.tt/1BZQwnH\" alt=\"Smile\" title=\"Smile\" title=\"v_middle\" />;


(Forgive me for syntactical errors like placing of single quotes and double quotes)


For your reference I've just added three <img> tags to the string but in real situation this string could contain a single <img> tag or no <img> tag or more than one <img> tags.


I want to get names of files present in each of the <img> tag's src attribute and make array of those file names. Then I have to replace these <img> tags by strings from an array titled $emoticon_codes which is created dynamically based on the file name present in <img> tag. This replacement of strings should happen is the same order.


For this I've tried following code. Till the creation of dynamic array titled $emoticon_codes everything works fine but I'm facing with code for replacing the current <img> tags with the strings from the array $emoticon_codes. So can somebody please help me in correcting the mistake I'm making in my code while replacing the <img> tags from the string.


Following is my code :



$doc = new DOMDocument();
$doc->loadHTML($feed_status);
$imageTags = $doc->getElementsByTagName('img');

if(count($imageTags)) {
$emoticon_codes = array();
foreach($imageTags as $tag) {
if (basename($tag->getAttribute('src')) == 'evilgrin.png') {
array_push($emoticon_codes, '\ue404');
}
if (basename($tag->getAttribute('src')) == 'grin.png') {
array_push($emoticon_codes, '\ue415');
}
if (basename($tag->getAttribute('src')) == 'happy.png') {
array_push($emoticon_codes, '\ue057');
}
if (basename($tag->getAttribute('src')) == 'smile.png') {
array_push($emoticon_codes, '\ue056');
}
if (basename($tag->getAttribute('src')) == 'surprised.png') {
array_push($emoticon_codes, '\ue107');
}
if (basename($tag->getAttribute('src')) == 'tongue.png') {
array_push($emoticon_codes, '\ue105');
}
if (basename($tag->getAttribute('src')) == 'unhappy.png') {
array_push($emoticon_codes, '\ue403');
}
if (basename($tag->getAttribute('src')) == 'waii.png') {
array_push($emoticon_codes, '\ue407');
}
if (basename($tag->getAttribute('src')) == 'wink.png') {
array_push($emoticon_codes, '\ue405');
}
}
/*Till here everything works fine. The array $emoticon_codes is also getting generated finely*/

/*Following is the code giving problem to me,*/
$t = 0;

foreach($imageTags as $img) {
$img->parentNode->replaceChild($img, $doc->createTextNode($emoticon_codes[$t]));
$t++;
if ($t > count($emoticon_codes)) {
break;
}
}
}


My desired output string should be like follows after echo $feed_status; :


$feed_status = Nice to see you all back again \ue056 \ue056 \ue056;


Thanks in advance.


What process needs to be followed in order to make a image search engine?

At first i want to implement basic machine learning algorithms and then move on to applying the concepts of deep learning.It will be very helpful if someone provides the related resources/tutorials in how to start building the search engine based on machine learning algorithms. Also which platform will be helpful to implement the search engine ?


How to show a split images 8x8 pixels?


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.Structure;

namespace DCTTransform
{
public partial class Form1 : Form
{
Image<Bgr, Byte> img;
Image<Ycc, Byte> imgYcc;
Bitmap bmp;

public Form1()
{
InitializeComponent();
}

private void btBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog od = new OpenFileDialog();
if (od.ShowDialog() == DialogResult.OK)
{
img = new Image<Bgr, byte>(od.FileName);
pcCitra.Image = img.ToBitmap();

label1.Text = img.Width.ToString();
}
}

//Split citra
public List<Image> subBlok(Image img, int blokX, int blokY)
{
List<Image> res = new List<Image>();
int pembagiLebar = img.Width / blokX;
int pembagiTinggi = img.Height / blokY;


for (int i = 0; i < blokX; i++)//baris
{
for (int j = 0; j < blokY; j++)//kolom
{
Bitmap bmp = new Bitmap(img.Width / pembagiLebar, img.Height / pembagiTinggi);
//Bitmap bmp = new Bitmap(img.Width, img.Height);

Graphics grp = Graphics.FromImage(bmp);
grp.DrawImage(img, new Rectangle(0,0 , bmp.Width, bmp.Height), new Rectangle(j * bmp.Width, i * bmp.Height, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
res.Add(bmp);
}
}


return res;

}


private void btTransform_Click(object sender, EventArgs e)
{
//SplitImage
List<Image> imgs = subBlok(pcCitra.Image, 8, 8);

pbDCT.Image = imgs[0];


}
}
}


I have made this code to divide an images became 8 x 8 pixels but the result shows just 1 block (8x8) on the upper left corner. all i want is like this |xxxx|xxxx|xxxx|xxxx|..........till the same width to original images


can you help me with this problem?


Keeping aspect ratio of image but cropping when hitting max/min height

I'm trying to make this image responsive that it will resize and keep it aspect ratio at all sizes. However above 650px, its height won't increase but will just crop the top and bottom to keep the ratio and not stretch. Also I want the image height won't go below 200px and just the left and right. I want image to always be center too. Here is what I have so far: http://ift.tt/1agniLG



<div class="hero">
<img src="http://ift.tt/1FfeakU">
</div>


.hero {
width: 100%;
min-height:200px;
max-height: 650px;
position: relative;
}
.hero img {
width: 100%;
height:auto;
min-height:200px;
overflow: hidden;
max-height: 650px;
position:aboslute;
}


Many thanks


How can I capture an image when AVPlayer playing m3u8 stream?

I use AVPlayer to play a m3u8 file, and I want to capture an image in these code:



AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:self.player.currentItem.asset];
gen.appliesPreferredTrackTransform = YES;
NSError *error = nil;
CMTime actualTime;
CMTime now = self.player.currentTime;
[gen setRequestedTimeToleranceAfter:kCMTimeZero];
[gen setRequestedTimeToleranceBefore:kCMTimeZero];
CGImageRef image = [gen copyCGImageAtTime:now actualTime:&actualTime error:&error];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
NSLog(@"%f , %f",CMTimeGetSeconds(now),CMTimeGetSeconds(actualTime));

NSLog(@"%@",error);
if (image) {
CFRelease(image);
}


but it does not work. And the error is: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x7fadf25f59f0 {NSUnderlyingError=0x7fadf25f1670 "The operation couldn’t be completed. (OSStatus error -12782.)", NSLocalizedFailureReason=An unknown error occurred (-12782), NSLocalizedDescription=The operation could not be completed}


How can I solve it? Thanks a lot.


Launch4j Icon Image Quality

I am currently using Launch4j to convert my JAR files to EXEs. While I was doing this, I added an image icon (ico). Now when I compile the program and the EXE is made, the icon image quality isn't great. But then if I rename the file, the quality is fine. Can someone tell me what is going on here and how to make it so that I don't have to rename the file to have good icon image quality? Thanks.


Can't set img using jquery from binary data from camunda process-definition

I'm trying to use camunda's REST API method, /process-definition/key/{key}/diagram, to return the image of the process definition.


When I run the following, the status is 200 and the data comes back as binary but not base64 encoded and the image doesn't render (note: when I have 'dataType' in, I get status=200 but err=No conversion from text to img/png).


Note: I ran it in google chrome Advanced Rest Client and same results; response header says content type is img/png


Does anyone know how to get this to render as an image? Thanks - Roger.



<html>
<head>
<title>Test</title>
</head>
<body>
<div id="getimage">Get image</div>
<div id="img123"></div>

<script src="http://ift.tt/13qgtmt"></script>

<script>
$(document).ready(function(){
$('#getimage').click(function(){
getImage();
});
});

function setImage(data){
$("#img123").append('<img src="data:image/png;base64,' + data + '"/>');
}

function getImage() {
console.log('Entered getImage!');

$.ajax({
url:'http://ift.tt/1akKvfK',
type: 'GET',
crossDomain: true,
headers: { "user":"demo","pwd":"demo","Access-Control-Allow-Origin":"http://127.0.0.1:8080/"},
//dataType: 'img/png',
success: setImage,
error: function (xhr, ajaxOptions, err) {
alert('ERROR: status=' + xhr.status + ' error=' + err);
}
});
}
</script>
</body>
</html>