AlexL Posted May 22, 2013 Share Posted May 22, 2013 Hi guys Firstly - I LOVE PROCESSWIRE! I've had a little bit to do with modx and kentico and boy do I love working in PW. Most problems I've been able to solve on my own due to the super helpful responses already in the forums - but I've hit a hitch. The core of the problem is the image resizer is not working for me. I believe that the issue relates to a file that has a .png extension but when I look at exif it is acutally a jpeg. So I want to rename it. When I load the image it is from an external URL //Bootstrap ProcessWire include("/[PATH]/index.php"); $page = new Page(); [FIELD SETTING FOR NEW PAGE] $page->save(); $page->Image = $row['imageUrl']; //$row is from previous MYSQL select $page->save(); so far so good - except now I want to pass that file through exif_imagetype to check what the actual image type is and then rewrite the file with the correct extension. Something like if (exif_imagetype($image->url) = IMAGETYPE_JPEG) { $image->ext = 'jpg'; } etc... However I'm getting 'Can't use function return value in write context' from the CLI for the exif command. Sorry it's so long winded I guess my questions are 1. Is it possible to pass the file to exif? What am I doing wrong above? 2. How do I programatically rewrite the extension? 3. Am I doing this completely wrong and should I be writing a hook? Thanks loads!!! Alex Link to comment Share on other sites More sharing options...
kongondo Posted May 22, 2013 Share Posted May 22, 2013 Welcome Alex! Ex-MODX-er here. Yes, PW is really awesome Our resident image (exif) etc expert is a guy called Horst. He (and others) will give you a better answer than me. Maybe the following threads would be helpful? http://processwire.com/talk/topic/238-creating-pages-using-api/ http://processwire.com/talk/topic/3219-images-manager-alpha/?p=33485 http://processwire.com/talk/topic/3398-working-with-processwire-getting-exif-data-from-images/ Link to comment Share on other sites More sharing options...
horst Posted May 22, 2013 Share Posted May 22, 2013 (edited) Hi Alex, welcome to the forum. I believe that the issue relates to a file that has a .png extension but when I look at exif it is acutally a jpeg. So I want to rename it. When I load the image it is from an external URL $page = new Page(); [FIELD SETTING FOR NEW PAGE]$page->save(); $page->Image = $row['imageUrl']; //$row is from previous MYSQL select$page->save(); To be save: your $page->Image is a real ImageInputfield that is assigned to a template?With [FIELD SETTINGS FOR NEW PAGE] you also have set the right template (that one that contains an ImageInputField named Image) ??Assuming the both questions answered with yes, you can pass the images filename to the exif_imagetype function: <?php $map = array( IMAGETYPE_JPEG=>'jpg', IMAGETYPE_PNG=>'png', IMAGETYPE_GIF=>'gif' ); $url = 'http://nogajski.de/_grafik/0815.png'; // a jpeg with wrong extension! $p = new Page(); // create page and assign image from url .... $p->save(); $p->Image = $url; $p->save(); $img = $p->Image->first(); // get your ImageObject, * read below ... $ext_im = $map[exif_imagetype($img->filename)];// compare imagetype against file extension $ext_fn = strtolower($img->ext); if($ext_im != $ext_fn) { // if not match, rename it $newFilename = str_replace('.'.$img->ext, '.'.$ext_im, $img->name); $img->rename($newFilename); $p->save(); } * how to get the imageObject depends a bit on your settings for the ImageField under Setup->Fields-> (your Image field) -> Details -> Maximum files allowed.If you have set it to 1 or if you allow multiple. (not really sure) but I think this could work for both situations EDIT: -> http://cheatsheet.processwire.com/ the FILES -> properties and ->methods() Edited May 22, 2013 by horst 3 Link to comment Share on other sites More sharing options...
AlexL Posted May 22, 2013 Author Share Posted May 22, 2013 OK - that looks exactly like what I'm after!! After reading your code I've just noticed the $file->rename and found it in the cheatsheet as well - feeling a little silly - thanks heaps!!! Can't wait to try it out - love learning all these new things Alex 1 Link to comment Share on other sites More sharing options...
horst Posted May 23, 2013 Share Posted May 23, 2013 After reading your code I've just noticed the $file->rename and found it in the cheatsheet as well - feeling a little silly There is so much to explore and learn with PW, - so, only overlook a single method isn't that bad. I have to go to CheatSheet too when writing the code example. First, before looking to the CheatSheet, I have tried with $img->path instead of your $img->url but the right property is $img->filename. It takes time to learn all the usefull stuff. The CheatSheet is my best friend besides the great people here. 1 Link to comment Share on other sites More sharing options...
AlexL Posted May 23, 2013 Author Share Posted May 23, 2013 OK!! Just implemented the code and it works out of the box! It has also resolved the underlying issue in relation to resizing - so happy!! Thanks Horst Alex 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now