Writing IPTC data to an image using iptcembed() in Codeigniter - php

I'm trying to write some IPTC data to an image within an upload form in Codeigniter.
I can get it to read out the data great, but I need to be able to write it too.
Basically when I try and write the data, I get this error:
Severity: Warning
Message: iptcembed() [function.iptcembed]: Unable to open
http://www.mydomain.com/photos/testimage1.jpg
Filename: controllers/upload.php
Line Number: 139
Trouble is, the URL is correct, I don't understand why it can't open the file. The file is uploaded before the iptcembed() is run to ensure that it can find the image.
Line 139 is:
$path = base_url()."photos/".$filename;
$filename is the filename of the file that is uploaded earlier in the function.
I'm using the first example from the PHP Manual to write the IPTC data.
Ideas?

Probably the solution has been found, but just to share.
My problem was the full url, probably in this case
"$path = base_url()."photos/".$filename;" the base_url is causing that troubles.

Related

podio api file upload from url

Have tried the API call as listed on Podio dev site to upload a file and I am not getting much joy.
I am trying to "Upload a file" in the first instance using the POST operation and passing the json with the source url to the endpoint as specified.
I can use other methods just fine but since there is little in the way or error feedback I am stuck I keep getting error 404
I have used - https://developers.podio.com/doc/files/upload-file-1004361
(have tried both GET & POST)
image of method with error i get
Upload file method that you are trying to use (https://developers.podio.com/doc/files/upload-file-1004361) is expecting file path which is supposed to be local file but not url.
Here is example of how it should be used:
http://podio.github.io/podio-php/api-requests/
$file = PodioFile::upload($path_to_file, $filename_to_display);
print 'File uploaded. The file id is: '.$file->id;
Here is another example on how to work with files:
https://developers.podio.com/examples/files

How to load an image from a URL into a PHP script and encode it as a base64 string?

I want to fetch an image from a URL, basically a resizing service, and then convert it to base64 string for consumption at client side.
I use the following code,
$imagePath = "www.xyz.com/resize/view.php?image=../pictures/abc.jpg&mode=crop&size=200x200";
$image = imagecreatefromstring(file_get_contents($imagePath));
$thumb_encoded = base64_encode($image);
echo "<br>".$thumb_encoded;
The $imagePath value, when opened in a browser works fine. Image is displayed.
But when running this script, the PHP throws the following error,
PHP Warning: file_get_contents(www.xyz.com/resize/view.php?image=../../pictures/abc.jpg&\amp;mode=crop&\amp;size=200x200): failed to open stream: No such file or directory in resizeImage.php on line 12
The & params in the URL which are needed for $_GET are getting converted to &\amp; while making the request in the PHP script.
I have tried urlencode() and htmlspecialchars($url) and html_entity_decode() and also escape characters, but in vain. I get the same/similar issues.
The image wont just load, the URL which the script queries is Wrong.
Can someone point out the issue here and help me?

Apple PNG Image Decompression

I have run into a problem with Apple's unfortunate decision to create a PNG file format that isn't actually a PNG file format. I pulled a PNG image file from an app IPA file and attempted to display it on a web browser and found that web browsers don't know how to display them and give an error. It took me some time to discover that the original, unzipped image was even the problem in the first place.
After researching the issue and doing a lot of poking around, I finally found this script as I don't have the knowledge to create a class to do what I need:
https://gist.github.com/juban/8397183
The author says this is a PHP scripted version that will turn an apple PNG file into a standard PNG file so that it can display properly. For added information, I am running PHP 5.5+.
My process of pulling out the image file goes like this:
if ($zip->open($ipaFile) === TRUE) {
if($zip->locateName($iconFilePath.$iconFile) !== FALSE) {
if ($iconData = $zip->getFromName($iconFilePath.$iconFile)) {
$iOSNormalizer = new iOSPNGNormalizer();
$iconData = $iOSNormalizer->getNormalizedPNG($iconData);
file_put_contents($iconSaveFile.$newIconFile, $iconData);
}
}
}
The iOSNormalizer is a class you can look at by clicking on the link I gave.
When I run it through the class I get hung up with the following errors:
Warning: zlib_decode(): data error in mypage.php on line 524
Notice: Uninitialized string offset: 12840 in mypage.php on line 532
Notice: Uninitialized string offset: 12840 in mypage.php on line 532
...These last two notices are repeated a ton of times for a lot of different lines. What happens is the apple PNG file has its original widths and heights restored, runs into the zlib_decode() error, and then stops working. The outputted file is a blank white image with its original height and width. zlib_decode() is not documented well for PHP and I'm not sure how to fix this problem. I'm hoping someone can look at the class in the link and better understand why this may be happening. Thanks!
EDIT: To ensure it isn't anything to do with how I am pulling out the icon file from the IPA file, I tested the following code on the image attached at at the end of my question and I still have the same problem (again, see the PHP class in my link to see what the function getNormalizedPNG() does):
$iconFile = "/path/AppIcon40x40#2x.png";
$newIconFile = "/path/converted.png";
$iOSNormalizer = new iOSPNGNormalizer();
$iconData = $iOSNormalizer->getNormalizedPNG($iconFile);
file_put_contents($newIconFile, $iconData);
Example PNG

Checking if the uploaded file is really a proper file or not (php)

Do the following steps to Understand the problem clearly :
Open notepad.
Type something and save it as " .png " (or any other image format).
Try to upload it as a image file with extension validation.
Now try to display it.
Expected : To show error while uploading
Actual : The file gets easily uploaded without any problem and error occurs only while accessing it.
mime_content_type() is deprecated function.
instead you can use
<?php
print_r(getimagesize("listing.png"));
?>
if this shows error then the file is invalid png file. If file is valid it returns an array of information.
Edit: This works if you are working with images only.

Preparing GD dynamic image for upload

How can I prepare a dynamic image created by GD for upload?
I created a php script to create dynamic images based on the userid (EX: www.mywebsite.com/image/124.png <== that should show the user 124 info)
Now I need to upload it to Facebook with this script :
$photo_details = array(
'message'=> $message
);
$file = "$_GET[id].png";
$photo_details['image'] = '#/home/username/public_html/image/' . $file;
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
When I use the upload script that way I get this error:
Fatal error: Uncaught CurlException: 26: failed creating formpost data
But If I uploaded 124.png to /image/ directory and and tried the same code again with using the ID 124 it works just fine. After a long research I came to conclusion the problem relay in the dynamic part since it works just fine with static images. How can I solve this problem?
Thank you so much for all the help.
Looks like the script tries to read the file directly from the filesystem instead of running the image generating script. You can solve this by setting $photo_details['image'] = 'http://www.mywebsite.com/image/'.$file; if Facebook class allows this kind of file opening.

Categories