Note that there are some explanatory texts on larger screens.

plurals
  1. POImage re-sizing not working with cakephp
    primarykey
    data
    text
    <p>I am trying to write a function which will upload a favicon and if said favicon is bigger than 16x16px then create a copy of it which is 16x16px. I'm using cakephp 2 and the function is called via ajax when a user enters a web address in a form on my site.</p> <p>So far the function works in that it gets the favicon ok, and if it's bigger than 16x16px then it renames the file as I want, but the code which is supposed to create the new smaller version is failing and I can't figure out why. I have looked at loads of other people's examples and from books but I don't know what my problem is, it all looks right to me.</p> <p>Here's the warnings that are returned when I alert whats echoed back from the function:</p> <p><b>Warning</b>: get_class() expects parameter 1 to be object, resource given in <b>C:\xampp\htdocs\xxxxxx\lib\Cake\Utility\Debugger.php</b> on line <b>578</b><br /> <br /> <b>Warning</b>: get_object_vars() expects parameter 1 to be object, resource given in <b>C:\xampp\htdocs\xxxxxx\lib\Cake\Utility\Debugger.php</b> on line <b>584</b><br /> <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>C:\xampp\htdocs\xxxxxx\lib\Cake\Utility\Debugger.php</b> on line <b>585</b><br /> <br /> <b>Warning</b>: ReflectionObject::__construct() expects parameter 1 to be object, resource given in <b>C:\xampp\htdocs\xxxxxx\lib\Cake\Utility\Debugger.php</b> on line <b>591</b><br /> <br /> <b>Fatal error</b>: Internal error: Failed to retrieve the reflection object in <b>C:\xampp\htdocs\xxxxxx\lib\Cake\Utility\Debugger.php</b> on line <b>593</b><br /></p> <p>And here's the function:</p> <pre><code>public function saveSiteFavicon() { $this-&gt;layout = 'ajax'; $url = $this-&gt;request-&gt;data['websiteurl']; $saveFileName = parse_url($url); $saveFileName = $saveFileName['host']; $saveFileName = str_replace('.', '', $saveFileName); $saveFileName = str_replace('www', '', $saveFileName); $this-&gt;Favicon-&gt;recursive = 0; $faviconexists = $this-&gt;Favicon-&gt;findByImage($saveFileName.'.png'); if(!empty($faviconexists)) { echo $saveFileName.'.png:'.$faviconexists['Favicon']['id']; } else { $fp = fopen ('img/favicons/'.$saveFileName.'.png', 'w+'); $ch = curl_init('http://g.etfv.co/'.$url); curl_setopt($ch, CURLOPT_TIMEOUT, 6); /* Save the returned data to a file */ curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); //if the favicon is oversized resize it $faviconFileName = 'img/favicons/'.$saveFileName.'.png'; $metaData=getimagesize($faviconFileName); if($metaData[1] &gt; 16) { rename($faviconFileName, 'img/favicons/'.$saveFileName.'_large.png'); $imgName='img/favicons/'.$saveFileName.'_large.png'; $thumbName='img/favicons/'.$saveFileName.'.png'; switch($metaData['mime']){ case 'image/jpeg': $img=imagecreatefromjpeg($imgName); break; case 'image/png': $img=imagecreatefrompng($imgName); break; case 'image/gif': $img=imagecreatefromgif($imgName); break; case 'image/wbmp': $img=imagecreatefromwbmp($imgName); break; } $imgThumb=imagecreatetruecolor(16,16); imagecopyresampled($imgThumb,$img,0,0,0,0,16,16,$metaData[0],$metaData[1]); imagepng($imgThumb, $thumbName); imagedestroy($imgThumb); } $this-&gt;Favicon-&gt;create(); $this-&gt;Favicon-&gt;save(array('image'=&gt;$saveFileName.'.png')); $faviconid = $this-&gt;Favicon-&gt;getLastInsertId(); //echo $saveFileName.'.png:'.$faviconid; } } </code></pre> <p>Can anyone tell me what I'm doing wrong.</p> <p><strong>EDIT :</strong> The problem is happening in this bit:</p> <pre><code>$imgThumb=imagecreatetruecolor(16,16); imagecopyresampled($imgThumb,$img,0,0,0,0,16,16,$metaData[0],$metaData[1]); imagepng($imgThumb, $thumbName); imagedestroy($imgThumb); </code></pre> <p>If I comment out the imagecopyresampled line, I don't get any errors. So something about imagecopyresampled is causing the debugger to fail in a function that Handles object to string conversion. </p> <p>here's the function in Debugger mentioned in the error messages </p> <pre><code>protected static function _object($var, $depth, $indent) { $out = ''; $props = array(); $className = get_class($var); $out .= 'object(' . $className . ') {'; if ($depth &gt; 0) { $end = "\n" . str_repeat("\t", $indent - 1); $break = "\n" . str_repeat("\t", $indent); $objectVars = get_object_vars($var); foreach ($objectVars as $key =&gt; $value) { $value = self::_export($value, $depth - 1, $indent); $props[] = "$key =&gt; " . $value; } if (version_compare(PHP_VERSION, '5.3.0') &gt;= 0) { $ref = new ReflectionObject($var); </code></pre> <p>Line 578 is the one </p> <pre><code>$className = get_class($var); </code></pre> <p>Obviously there's more to the function but all errors are happening in those lines.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload