- $image = $this->imageTool->make($imageData);
- $image->resize(32, 32);
- $bmpData = $image->encode('bmp');
- $icoData = $this->bmpToIco($bmpData, 32, 32);
-
- // TODO - Below are test paths
- file_put_contents(public_path('uploads/test.ico'), $icoData);
- file_put_contents(public_path('uploads/test.bmp'), $bmpData);
-
- // TODO - Permission check for icon overwrite
- // TODO - Write to correct location
- // TODO - Handle deletion and restore of original icon on user icon clear
+ $pngData = $this->imageResizer->resizeImageData($imageData, 32, 32, false, 'png');
+ $icoData = $this->pngToIco($pngData, 32, 32);
+
+ file_put_contents($this->path, $icoData);
+ }
+
+ /**
+ * Restore the original favicon image.
+ * Returned boolean indicates if the copy occurred.
+ */
+ public function restoreOriginal(): bool
+ {
+ $permissionItem = file_exists($this->path) ? $this->path : dirname($this->path);
+ if (!is_writeable($permissionItem)) {
+ return false;
+ }
+
+ return copy($this->getOriginalPath(), $this->path);
+ }
+
+ /**
+ * Restore the original favicon image if no favicon image is already in use.
+ * Returns a boolean to indicate if the file exists.
+ */
+ public function restoreOriginalIfNotExists(): bool
+ {
+ if (file_exists($this->path)) {
+ return true;
+ }
+
+ return $this->restoreOriginal();
+ }
+
+ /**
+ * Get the path to the favicon file.
+ */
+ public function getPath(): string
+ {
+ return $this->path;