mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-16 04:10:09 -07:00
Improve Imagine image loaders
This commit is contained in:
parent
a6fab6c0be
commit
e5e50e8010
@ -8,6 +8,7 @@ set:
|
||||
minifigs: Minifigs
|
||||
rating: Rating
|
||||
reviews.link: View all reviews on Brickset.com
|
||||
image.alt: Image of set '%number%'
|
||||
models:
|
||||
text: |
|
||||
This set inventory has been obtained from Rebrickable.
|
||||
@ -69,6 +70,7 @@ model:
|
||||
aliases: Aliases
|
||||
download: Download brick
|
||||
empty: No model
|
||||
image.alt: Image of brick '%number%'
|
||||
form:
|
||||
search: Search
|
||||
category: Category
|
||||
@ -138,6 +140,7 @@ part:
|
||||
molds: Molds of part
|
||||
prints: Prints
|
||||
sets: Sets
|
||||
image.alt: Image of part '%number%'
|
||||
|
||||
form:
|
||||
search.submit: Search
|
||||
|
@ -6,7 +6,9 @@
|
||||
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
||||
{% endif %}
|
||||
|
||||
<img src="{{ placeholder }}" data-src="{{ asset(color~'/'~number~'.png') | imagine_filter(filter) }}" alt="{{ number }} - image">
|
||||
<img src="{{ placeholder }}"
|
||||
data-src="{{ asset(color~'/'~number) | imagine_filter(filter) }}"
|
||||
alt="{{ 'part.image.alt'|trans({'%number%':number}) }}">
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@ -18,7 +20,9 @@
|
||||
{% set placeholder = asset("resources/images/transparent_min.png") %}
|
||||
{% endif %}
|
||||
|
||||
<img src="{{ placeholder }}" data-src="{{ asset(number~'.jpg')|imagine_filter(filter) }}" alt="{{ number }} - image">
|
||||
<img src="{{ placeholder }}"
|
||||
data-src="{{ number|imagine_filter(filter) }}"
|
||||
alt="{{ 'set.image.alt'|trans({'%number%':number}) }}">
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
@ -31,21 +31,25 @@ class PartImageLoader extends BaseImageLoader
|
||||
|
||||
public function find($path)
|
||||
{
|
||||
$localPath = '/images/'.$path.'.png';
|
||||
|
||||
// try to load image from local mediaFilesystem
|
||||
if ($this->mediaFilesystem->has('/images/'.$path)) {
|
||||
return $this->mediaFilesystem->read('/images/'.$path);
|
||||
if ($this->mediaFilesystem->has($localPath)) {
|
||||
return $this->mediaFilesystem->read($localPath);
|
||||
}
|
||||
|
||||
$rebrickablePath = $this->rebrickableContext.strtolower($path).'.png';
|
||||
|
||||
// try to load image from rebrickable website
|
||||
if ($this->remoteFileExists($this->rebrickableContext.$path)) {
|
||||
if ($this->remoteFileExists($rebrickablePath)) {
|
||||
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
||||
|
||||
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
|
||||
return file_get_contents($rebrickablePath, false, $context);
|
||||
}
|
||||
|
||||
// Load part entity form rebrickable api and get image path from response
|
||||
try {
|
||||
if (preg_match('/^(.*)\/(.*).png$/', $path, $match)) {
|
||||
if (preg_match('/^(.*)\/(.*)$/', $path, $match)) {
|
||||
$part = $this->rebrickableManager->getPart($match[2]);
|
||||
|
||||
if ($part && $part->getImgUrl()) {
|
||||
|
@ -29,28 +29,28 @@ class SetImageLoader extends BaseImageLoader
|
||||
$this->mediaFilesystem = $mediaFilesystem;
|
||||
}
|
||||
|
||||
public function find($path)
|
||||
public function find($setNumber)
|
||||
{
|
||||
$rebrickablePath = $this->rebrickableContext.strtolower($setNumber).'.jpg';
|
||||
|
||||
// try to load image from rebrickable website
|
||||
if ($this->remoteFileExists($this->rebrickableContext.strtolower($path))) {
|
||||
if ($this->remoteFileExists($rebrickablePath)) {
|
||||
$context = stream_context_create(['http' => ['header' => 'Connection: close\r\n']]);
|
||||
|
||||
return file_get_contents($this->rebrickableContext.strtolower($path), false, $context);
|
||||
return file_get_contents($rebrickablePath, false, $context);
|
||||
}
|
||||
|
||||
// Load part entity form brickset api and get image path from response
|
||||
try {
|
||||
if (preg_match('/^(.*)(.png|.jpg)$/', $path, $match)) {
|
||||
$set = $this->bricksetManager->getSetByNumber($match[1]);
|
||||
$set = $this->bricksetManager->getSetByNumber($setNumber);
|
||||
|
||||
if ($set && $set->getImage()) {
|
||||
return file_get_contents($set->getImageURL());
|
||||
}
|
||||
if ($set && $set->getImage()) {
|
||||
return file_get_contents($set->getImageURL());
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new NotLoadableException(sprintf('Source image %s could not be loaded.', $path), $e->getCode(), $e);
|
||||
throw new NotLoadableException(sprintf('Image %s could not be loaded.', $setNumber), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
throw new NotLoadableException(sprintf('Source image %s not found.', $path));
|
||||
throw new NotLoadableException(sprintf('Image %s not found.', $setNumber));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user