I am using QRICKIT (qrickit.com) to generate QR codes. Instead of generating codes every time the page refreshes, I want to download them and use the ones already generated.
So, within the loop that iterates through my database table, I do this:
$qrcodebase = "https://qrickit.com/api/qr.php?d=";
$filename = "./product_images/" . $row["itemID"] . "_QR.png";
if (!(file_exists($filename))) {
$url = $qrcodebase . $myurl . $brandpage . "/?itemID=" . $row["itemID"];
file_put_contents($filename, file_get_contents($url));
}
echo "<td><img src=\"" . $filename . "\" height=60 width=60></td>";
When this executes, it generates the right HTML to display the image, and when I FTP to the product_images folder, the QR codes are there. When I download the QR codes and open them up in an image editor, they open just fine. But, when the web page displays, I get an X in a box that indicates a bad image. Does anyone have any idea why?
Related
I have a requirement where i need to extract the content from the images. Now i have been successful in doing that when it comes to extracting the entire content from an image using the below command .
shell_exec("/usr/bin/tesseract inv.jpg invoice -l eng");
$data = file_get_contents('invoice.txt');
echo '<pre>';
print_r($data);
This gives me the entire content. Now i need to know how to go about extracting the data only from a specific portion of an image using the co-ordinates .
Any advice would be helpful .
Thanks.
I made a little trial using JS upon canvas and images. The final part of it calls a page where at the beginning I try to write upon the server the final image.
The process supposes that a previous file exists, not complete:
<?php
$filename = explode(".", $_POST["trans_file"]); // name of the image file
if (!unlink("transit/" . $_POST["trans_file"])) echo "File " . $_POST["trans_file"] . "not found!<br />"; // remove the partial file
$filesave = $filename[0] . ".png"; // I will save a PNG file
$filejpg = $filename[0] . ".jpg"; // but I will transform it into JPG
$data = $_POST["base64img_data"]; // here I receive the base64 image by a previous process
$data = explode(";", $data); // I remove the first part of it
$data = explode(",", $data[1]); // $data[1] now contains the base64 image complete
$image=base64_decode(chunk_split($data[1])); // $image is now a PNG file
$handle = fopen("transit/$filesave", "wb"); // Create a PNG file
fwrite($handle, $image); // write it
fclose($handle); // Close, and transform it into JPG
png2jpg("transit/$filesave", "transit/$filejpg", 100);
unlink("transit/$filesave"); // remove PNG image
I've put this at the beginning of the page, but the browser always displays the previous file, the one cancelled at the beginning, and being itself a JPG.
Strange enough (for me) this sequence is working perfectly on one server, not working on a different one!
I suppose it could be a case of asynchronous execution of PHP and JS inside the page.
How may I synchronize server and browser?
Thank you.
what happens if one process writes to the file and in the middle of the operation another process deletes it?
use .lock files so only 1 process tries to manipulate the files in question.
I wrote a quick PHP script for loading an image in a directory, but I've been finding that it regularly gives me "Image truncated or corrupt" errors in the Error Console, despite the images not being corrupt. I'm able to view the image normally if I browse to its full path, and I'm also able to download it and view it without issue. I've tried using different browsers but have the same problem.
Oddly enough, some images work fine and some do not. The issue doesn't seem to be related to file size.
My code is pretty simple, and I've been using it for ages:
if (isset($_GET['i']) && is_numeric($_GET['i'])) {
$path = 'D:/Images/';
if (is_file($path . $i . '.jpg')) {
header('content-type: image/jpg');
require($path . $i . '.jpg');
}
You shouldn't be using require, that includes the image as if it were PHP code. You should be using readfile(), which will just open the image and send it straight to the browser:
readfile($path . $i . '.jpg');
exit;
Also note that you'll want to call exit() after readfile().
My HTML page displays an image with the following code (using Flickr)
<?php
echo '<img src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
?>
The thing is that I'd like to resize this image to then display it on the page and I don't know how to do that.
Often sites such as flickr allow you to request different sized versions of the image so your best bet is likely to be to request an appropriately sized image.
I'm not sure of the exact details but I looked at http://www.flickr.com/photos/29609591#N08/5735893153/sizes/z/in/photostream/ (a photo I found on the front page of the site) and there are links to different sizes. They seem to be in the same form as yours with the addition of _x just before the .jpg (where x is a letter dependant on size).
I couldn't find any documentation on this in a quick search but in this case we had:
_s for a square
_t for a thumbnail
_m for a small
(no extension) for a medium 500
_z for a medium 640
_b for a large
_o for original - this url seems to be different from the others
I suspect the criteria for these is by fitting to an upper limit of dimensions but I don't know for sure. Trial and error may help you out.
Add width and height attributes to your html string.
<?php
echo '<img width='200px' height='200px' src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
?>
here I have to cache about 2000 favicon.ico files for performance enhancements. I grab the files and try to shrink them via IMagick (v.6.6.0) and PHP 5.3.5
The PHP code for this is
try {
$image = new Imagick($im_hint . ':' . BASE . '/upload/favicon.ico');
$image->cropThumbnailImage(16, 16);
$image->setImageFormat('ico');
$image->writeImage(BASE . '/favicons/' . $id[0] . '/' . $id[1] . '/' . $id[2] . '/' . $id . '.ico');
} catch (Exception $e) { die($e->getMessage()); }
where $im_hint could be ico, png, jpg and so on.
For 99% of the files all is fine and I get a working ICO file. But for one percent of files, I get only a blank ICO file and I don't know why? An example for an ICO file where this code fails is http://www.augensound.de/favicon.ico
I tried to comment out the cropThumbnailImage call and try to use setFormat instead of setImageFormat and tried to save it as PNG...but nothing works. There is also no exception.
Regards
Not an answer to your question, but I get a blank image too when I open the example file in IrfanView or PhotoImpact. It's not a multi-page/multi-resolution file so there is nothing to switch. The canvas just is blank.
Windows 7's built-in preview renders it fine, though.
It could be that IM can't deal with these files because they have the wrong format or sub-format.