iOS file system: adding/removing/sorting files - objective-c

I have a directory with images like this:
0000.png
0001.png
0002.png
0003.png
etc...
To add an image, I query the count of the directory and name the new file with the count. I need to maintain such an order because these images are eventually displayed in a grid view. This is the easy part. What is bugging me is manipulating the directory later.
The user can delete and reorder these as they wish. So how should I handle reordering of the actual directory?
I have tried, naively, copying the images into an NSMutableArray, loading those into the gridView, letting the user manipulate, then upon finish I wipe the directory and rewrite the images. That's fine for a few images, but there can be many and it slowly builds up.
I like the idea of copying the images locally, manipulating and then fixing the directory. But I think there has got to be a better way to manage the directory instead of wiping and rewriting, would it be faster to write some kind of file-swapping method?

Instead of writing the images to the file system in an ordered format, you could have a meta data file images.plist
And maintain an NSMutableArray of NSDictionaries
Each dictionary will contain the data for the imageFile Path and the image index
Then when you would save the changes of the user you will only rewrite this plist file, instead of saving all the images again

Related

What is the best place to store module uploaded images

I am creating a module that allows to create some objects and upload images for them.
For the moment, I am uploading images in the module folder itself. But I think it is better to store them in PS img folder like for product and category images. One of the reasons is to avoid their deletion when module is deleted mistakenly from backoffice.
Is there any other reason to store/ not store images in img folder? What is the best place to store a huge number of uploaded images?
Your ideas are much appreciated. Thanks in advance.
Yes, it's better to save your images in the img folder. The most important reason for doing this: this route will never be blocked by robots.txt.
In my modules, (in order to be more orderly,) I create a folder called "module" and then inside this folder, I create another folder called the my-module-name.
img/modules/my-custom-module/test.jpg

Ghostscript - create a pdf with multiple identical pages and keep size down

Im trying to use Ghostscript to create a PDF with multiple identical pages. I will later use this together with another multipaged PDF to stamp on unique information onto every page.
Is it possible to use Ghostscript to create such a PDF and keep the size of the final file down? Maby there is a flag that i have not noticed that can do this in a better way than the script below?
I have tried to use a regular merge command like the one below but the size of the resulting PDF grows alot and the original file size of 2,061MB merged to a 100page pdf results in a final size of 46,117MB.
"C:\Program Files\gs\gs9.20\bin\gswin64.exe"^
-dBATCH^
-dNOPAUSE^
-q^
-sDEVICE=pdfwrite^
-sOutputFile=outputpdf.pdf^
"inputpdf.pdf"^
"inputpdf.pdf"^
"inputpdf.pdf"(and so on 100 times)
You can construct such a file manually easily enough, which is much smaller, by reusing the page content stream for each page.
However Ghostscript's pdfwrite device won;t do that, not least because it can't. It cannot know in advance that the page its about to receive is the same as the previous page. As a result it will create a new page content stream for each page, and create new content for it.
Note that resources (forms, patterns, colour spaces, image XObjects etc) which are used on each page will be reused on other pages.
However, it seems to me that you're already getting nearly a 5:1 ratio (2k * 100 pages = 200Kb, the final file is 46Kb) though in fairness a good bit of that 2Kb is 'stuff' around the page.
Without seeing your input file I can't really comment any further, but frankly I doubt its possible to make it any smaller without hand-crafting the file. What's the problem with a 46Kb file anyway ?

Is it possible to have image resizer replace our existing different sized image folder structure?

Our current image folder structure consists of the same image at different sizes for use within our website
Content/thumb/5316.jpg
Content/ShotView/5316.jpg
Content/miniview/5316.jpg
Content/Full/5316.jpg
Is it possible to have imageresizer handle/rewrite the requests to the smaller size images as calls to the Full image with default height/width parameters depending on the folder selected can I do this via a combination of IIS virtual directories and default settings?
So we could retain our existing structure but as products change we would only need the 1 original image?
All you would need is some URL rewriting; no need for Virtual Directories.
The Config.Current.Pipeline.Rewrite even will let you parse and edit the path and querystring in code, which is the most flexible solution.
IIS URL Rewrite, however, is also capable of solving your problem.

path of suporting files in OS X program?

I need some help for my OS X program.
I need the URL of a file inside the supporting files.
I have an array in which I save URLs from images and add them to a table view and if no images are chosen I want to add a question mark image (it is called "bild.jpg")
This bild.jpg is inside the supporting files but for later use I can't just save the name of the image because the array stores also URLs.
I need to have the URL of that image in the supporting file because it's easier to use the array for image initialization.
Is there a function to get the path or is there a standard path to the supporting files? I already search on the net but couldn't find anything that could help.
You seem to be talking about the application bundle and its resources directory rather than, say, a subdirectory in ~/Library/Application Support/..., in which case you probably want something like:
[[NSBundle mainBundle] URLForResource:#"bild" withExtension:#"jpg"]
(See the documentation for NSBundle.)

ProcessingJS - loadImage() and loadStrings() path problem

I have a path problem when using loadImage() and loadStrings() in Processingjs. I would like to have my sketches and their associated files (images, text files) in one place and to be able to call them from another on my site.
For example, I am trying to run a Processingjs sketch located at
www.example.com/sketches/mysketch.pde from the page www.example.com. This works fine when there are no external files.
Alas the problem starts when I need to use loadImage() and loadStrings() to look for images and texts to load. It defaults to www.example.com/image.jpg and not to the sketch location, www.example.com/sketches/image.jpg.
The need for #pjs preload makes matters worse.
Without moving the files and without hardcoding, is there a way to
tell Processingjs to look for the files to load in the same folder as
the .pde and not the .html?
I hope this is clear. Any help would be appreciated!
Short answer: no.
Even native Processing won't behave the way you want in this sense, because you'll be executing your sketch from [...]/sketches/ and any resource call is local to that directory.
Similarly, with processing.js your resources are located relative to the "directory" you're in, which for www.example.com/ is just the base dir. What you can do, however, is place your .pde file in the same dir as your .html file, or vice versa.
#pjs preload is necessary to effect "immediate" file loading. If you don't preload it, your sketch will have to deal with asynchronous load instructions. Quite literally, loadImage without a preload directive behaves the same as requestImage (http://processing.org/reference/requestImage_.html)