/** * Generate icons for an entity * * @param ElggEntity $entity * @param ElggFile $filehandler Valid $filehandler on Elgg filestore to grab the file from | can be null if $entity is instance of ElggFile * @param array $coords Coordinates for cropping * @return boolean */ function hj_framework_generate_entity_icons($entity, $filehandler = null, $coords = array()) { $icon_sizes = hj_framework_get_thumb_sizes($entity->getSubtype()); if (!$filehandler && $entity instanceof hjFile) { $filehandler = $entity; } if (!$filehandler) { return false; } $prefix = "icons/" . $entity->getGUID(); foreach ($icon_sizes as $size => $values) { if (!empty($coords) && in_array($size, array('topbar', 'tiny', 'small', 'medium', 'large'))) { $thumb_resized = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], $coords['x1'], $coords['y1'], $coords['x2'], $coords['y2'], $values['upscale']); } else { if (empty($coords)) { $thumb_resized = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']); } } if ($thumb_resized) { $thumb = new hjFile(); $thumb->owner_guid = $entity->owner_guid; $thumb->setMimeType('image/jpeg'); $thumb->setFilename($prefix . "{$size}.jpg"); $thumb->open("write"); $thumb->write($thumb_resized); $thumb->close(); $icontime = true; } } if ($icontime) { $entity->icontime = time(); return true; } return false; }